ocaml %identity function
I'm wondering why do we need function like "%identity", which is the same as let a = a. Is it going to improve performance by using it ?I'm introducing phantom typing in my program, calling identity...
View ArticleComplexity of this function
I would like to know how to properly determinate the complexity of this function :let rec fact n = match n with | 0 -> 1 | n -> n * fact (n - 1)let biggest_factorial_below n = let i = ref 1 in...
View ArticleIf statements questions in OCaml
I am trying to write the following code in OCaml:let a = 0let b = 1 if a > b then { print_endline "a"; print_endline "a"; }print_endline "b"And then I encountered the following error:File "[21]",...
View ArticleCompile a one file ocaml program with a module and a main method
I somehow can't install a working OCaml environment on my Windows computer. I want to use know the OCaml online compiler. Problem: I can only write one file there and put everything in that one...
View ArticleWhy is dune refusing to download dependencies?
I expected dune to automatically download dependencies when running dune build, but that doesn't happen.I've tried multiple variants of this, and I tried with ocaml versions 4.14 and 5.0, and with...
View ArticleOCaml function need clarification
I am trying to write an OCaml function that takes a list of list and return the longest list of them and I keep getting that n.length and l.length is unbound record field lengthlet rec longest (nss: 'a...
View ArticleOCaml `Map.Make` input module
I am following the example here.module IntPairs =struct type t = int * int let compare (x0,y0) (x1,y1) = match Stdlib.compare x0 x1 with | 0 -> Stdlib.compare y0 y1 | c -> cendmodule PairsMap =...
View ArticleAccess the element at a list with index
In OCaml, I want to write a function that returns the element at a given index of a list. For example [4;5;6] 0 -> 4, [4;5;6] 1 -> 5. I know how to do this recursively, but can anyone show how to...
View ArticleDisable automatic undindent for `in` keyword for OCaml in VSCode
I am programming in OCaml using VSCode, but each time I begin a line with the in keyword, the editor automatically unindent the line. This is really annoying and I would like to disable this particular...
View Articleis it possible to write monadic parser as clean as that in haskell?
Assuming we are going to parse an expression like this:Exp := MulMul := Add {'*' Add}Add := Literal {'+' Literal}Literal := number | '(' Exp ')'In Haskell, we can write a parser likeexp = mulmul = do...
View ArticleIs it possible to write recursive monadic parser in OCaml? [closed]
Assuming we are going to parse an expression like this:Exp := MulMul := Add {'*' Add}Add := Literal {'+' Literal}Literal := number | '(' Exp ')'In Haskell, we can write a parser likeexp = mulmul = do...
View ArticleUnbound module Eio-posix
I am trying to disable Windows symlinking tests in my OCaml code. However, when I run my tests, I encounter the following error message: Unbound module: Eio_posixI installed the Eio library using opam,...
View ArticleMake a function return itself after doing some work
let log x = print_int x; log ;;log 111 222;;I am expecting log to print 111 and return itself and then print 222 on the second call but it does not work as expected, I am getting an error message...
View ArticleMake OCaml function polymorphic for int lists and float lists
Is there a way to create a polymorphic add function in OCaml that works equally well for ints and floats? So for example if I have a function like:partialsums [1; 2; 3; 4; 5] I should get [1; 3; 6; 10;...
View ArticleWhy does the OCaml function `read_line` have type `unit -> string`?
I understand that its return type is the string that is read but why does it need the parameter of type unit?
View ArticleI don't understand why the result of the last statement is 6
let x = 2;;let x = 3in let y = x +1 in x + 1;;let x = 3 and y = x + 1 in x + y;;The results are ordered respectively to each expression:val x : int = 2- : int = 7- : int = 6Can you help me understand...
View ArticleLocally abstract type VS explicit polymorphism in polymorphic recursion context
Could you explain me why this program does typechecklet rec plop1 : 'a 'b 'c. 'a -> 'b * 'c = fun x -> (fst (plop1 ""), snd (plop1 1))while this one does not?let rec plop2 (type a b c) (x : a) :...
View ArticleUncertain of how to read OCaml function type signatures
Could someone explain to me the following type? Specifically the return type.string list -> (string * string * string) list
View ArticleDesigning an Interpreter in OCaml [closed]
Does anyone know how to write an interpreter in OCaml? So let's say I have a paper on an abstract machine/langauge called LangABC; How do i approach writing an interpreter that can understand and test...
View Articlein Ocaml Ppxlib extension with two or more parameter
Could you give code of OCaml PPX extension to rewrite expressions of the form[%add a b] into a + b. Specifically, I'm looking for an extension that will:Recognize and match the construct [%add a b],...
View Article