OCaml cons (::) operator?

11 No. Cons (::) is a constructor, constructors can not be infix operators. The allowed infix symbols are here: http://caml.inria.fr/pub/docs/manual-caml-light/node4.9.html Some workarounds are (as you mention) the verbose and defining your own nontraditional infix cons

OCaml mod function returns different result compared with %

Python is a bit different in its usage of the % operator, which really computes the modulo of two values, whereas other programming languages compute the remainder with the same operator. For example, the distinction is clear in Scheme: In Python: But in OCaml, there’s only mod (which computes the integer remainder), according to this table and as stated in the documentation: Of course, you can implement … Read more

“Error: unbound module” in OCaml

You have several options depending on your needs. 1) If you want to create a full project for your binary I recommend looking at jbuilder. Here is a very nice guide that explains the environment/project configuration step-by-step: OCaml for the impatient. 2) Another option is to compile the binary directly as you were trying to … Read more

What does the `and` keyword mean in OCaml?

The and keyword is used either to avoid multiple let (first example, I never use it for this but why not) or for mutually recursive definitions of types, functions, modules… As you can see in your second example : debug calls debugl and vice versa. So the and is allowing that. [EDIT] It bothered me … Read more

OCaml: Match expression inside another one?

Quick Solution You just need to add parentheses, or begin/end, around the inner match: Simplifications In your particular case there is no need for a nested match. You can just use bigger patterns. You can also eliminate the duplication in the nested rules using “|” (“or”) patterns: You can make it even more readable by replacing … Read more

Print a List in OCaml

You can do this with a simple recursion : The head of the list is printed, then you do a recursive call on the tail of the list.

IDE for OCaml language

Editors • Emacs ◦ ocaml-mode from the standard distribution ◦ alternative tuareg-mode https://forge.ocamlcore.org/projects/tuareg/ − cheat-sheet: http://www.ocamlpro.com/files/tuareg-mode.pdf ◦ camldebug intergration with debugger ◦ type feedback with C-c C-t key shortcut, needs .annot files • Vim ◦ OMLet plugin http://www.lix.polytechnique.fr/~dbaelde/productions/omlet.html ◦ For type lookup: either https://github.com/avsm/ocaml-annot − or http://www.vim.org/scripts/script.php?script_id=2025 − also? http://www.vim.org/scripts/script.php?script_id=1197 • Eclipse ◦ OCaml Development Tools http://ocamldt.free.fr/ ◦ an old plugin OcaIDE http://www.algo-prog.info/ocaide/ … Read more

List.fold_left in OCaml

fold_left operates on lists, as your function does, by applying a function and accumulating a result in a particular manner. It takes care of and abstracts the recursion for you. It deals with the structure of the list, so you can deal with how to combine the elements of the list in a particular manner. So, … Read more

error code: 523