Infix operators with 3 parameters ocaml
Is it possible in ocaml to define an operator like the array set function which can be written a.(n)<-v?The OCaml manual explains how to define 2-parameters infix operators but not 3-parameters...
View ArticleFast intersection of two N^4 sets
I'm looking for an algorithm that returns (the length of) the intersection of two given N^4 lists / sets (more precisely in [|0;7|]^4). I'm not expecting an answer in a specific programming language...
View ArticleOCaml for-loop seems to be re-executing more than expected
I have the following functionlet update s = for i=0 to ((Array.length s) - 2) do for j=0 to (Array.length (s.(i))) - 2 do (s.(i)).(j) <- (s.(i).(j)) + 1; done; doneand it seems to increase the...
View ArticleHow to write sublist of a char list as [’1’; ’2’; ’3’; ’’; ’’; ’4’; ’5’; ’’;...
I am currently learning OCaml and i couldn't make sublist even thought I can make a list without spaces as ['1'; '2'; '3'; '4'; '5'; '6']. I couldn't find any sources to my question so thanks for...
View Articlez3 OCaml module linking error in "dune utop"
I have to execute z3 module in OCaml.But when I try to execute dune utop then I meet under errormingyu809@DESKTOP-NTK8E0T:~/ocaml/COSE419-2024-main/hw2$ dune utopFile "_none_", line 1:Error: Error on...
View ArticleHow to convert non-built-in types to string in Ocaml?
I'm trying to write a module that convert something like x:int = if true then 3 else 5 to a stringHere's the code I have so farmodule Ast =structtype typ = Bool | Inttype var = A | B | C | D | E |...
View ArticleCreate a tuple list from a list using fold_left
How to create a tuple list from one single list, like so:[1; 2; 4; 6] -> [(1, 2); (4, 6)]I want to do it using function List.fold_left since I'm trying to learn that currently but don't know how......
View ArticleReversing tuples inside a list with fold_left in Ocaml
Let lst be a List with tuples which I want to reverse each (The order of the tuples needs to be the same). For example:[(a,b);(c,d)] -> [(b,a);(d,c)] I know that it can be done with map:List.map...
View ArticleUsing infix operator in the module in OCaml
I am trying to define a SCALAR signature with its own infix operator inmodule type SCALAR =sig type t (* type of scalar element *) val zero : t val one : t val (++) : t -> t -> t (* infix...
View ArticleInterleaving in OCaml
I am trying to create a function which interleaves a pair of triples such as ((6, 3, 2), ( 4, 5 ,1)) and create a 6-tuple out of this interleaving.I made some research but could understand how...
View ArticleHow does a compiler determine whether a string matches a regex or not? [closed]
I've recently been learning about compilers, more specifically Ocaml ones, and I was wondering how does the compiler actually determine which regex a string matches. Does it build a DFA for each regex...
View ArticleCompiling OCaml .cmm file
I wrote simple OCaml code like:let rec fib(n: int) = match n with | 0 -> 0 | 1 -> 1 | _ -> fib(n-1) + fib(n-2)With -dcmm option to ocamlopt, I could generate .cmm files...
View ArticleWrite a function that returns every other element of the list
I want to write a function that can return every other element of the list like this ['a' ; 'b' ; 'c' ; 'd' ; 'e'] can return: ['a' ; 'c' ; 'e']My function can use only with predefined functions...
View ArticleList.filter and List.mem [closed]
I am having a problem understanding this particular linelet lst = ["a", "b", "c"];List.filter (fun (a, _b) -> not (List.mem a lst)) assoc
View Articlethis pattern-matching is not exhaustive in OCaml
I am new in OCaml and I wrote some code to get the n element of a listlet rec n_elem l n = match n with| 0 -> match l with | h::_ -> h | _ -> failwith "erorr with empty list"| _ -> match l...
View ArticleGlade and Ocaml?
I'm currently working on a project in Ocaml (I love this language), and I need to create a graphical interface. I've tried LabelGTK, it works but it's REALLY tiring... As a regular Glade user, I'd like...
View ArticleOCaml - is enumeration over custom union type possible?
Having a disjont union type like this:type yolo = | A | B | CIs it possible in OCaml to iterate/enumerate over each possible value of type yolo without prior knowledge of how many/what these values...
View ArticleOCaml map of int keys :: where is the 'simple' int module to use with the...
I need an OCaml map with keys of type int so I am using Map.Make to create one. However it seems that the standard modules'only' provide modules like Big_int, Int32, Int64 and Nativeint which require...
View ArticleIs enumeration over custom union type possible?
Having a disjoint union type like this:type yolo = | A | B | CIs it possible in OCaml to iterate/enumerate over each possible value of type yolo without prior knowledge of how many/what these values...
View Articleopam install ocaml-lsp-server is not working
trying to install, but getting the following message. Constructing initial basis... The following dependencies couldn't be met: - ocaml-lsp-server → dyn → ocaml >= 4.08.0 base of this switch (use...
View Article