Recursive Ocaml program at the tail

I'd like to turn the function met_devant_et_acc into a tail-recursive one but i don't know how i can re-write it. met_devant_et_acc l h is supposed to return a list containing all the list of the list l and all these same lists with the element h as

Execute the decoding of the length in OCaml

In my function below, lp is of form as in example [0,a;3,r;7,p;2,a]. The function run_length_decode takes lp and returns in above example [r;r;r;p;p;p;p;p;p;p;a;a]. let rec run_length_decode lp = match (List.hd lp) with [] ->[] | [0] -> rle_decode (

Use s-expression in OCaml utop

I am learning OCaml with a book titled as "Real World OCaml" and so far it works well. I have a problem with sexp and Sexplib. # module type M = sig # type t with sexp # end;; This is a textbook example but I have a syntax error in utop, with wi

how to force to start the next expression in ocaml

I want to write a function that implements basic usage of grep: matching a pattern in a file. And I want to match_file_pattern to return a list of matched lines. But the code here cannot compile, the error is: Error: This expression has type string l

js_of_ocaml.ppx not found

I'm trying to run js_of_eliom, but it seems that it don't have ppx_deriving This is the message i got when i do a make: js_of_eliom -ppx -c -package lwt -package js_of_ocaml.deriving -package js_of_ocaml.ppx simple_pomodoro.eliom Fatal error: excepti

Include the submodule of a functor application

I have this functor that has a submodule: module type PT = sig type t val to_string: t -> string end module A(P:PT) = struct module SubA = struct type t = T of P.t | F of float end end And I want to extend it using an include. This even works: module

The main function in OCaml

From a programmer trained in a C world, this is my main method for OCaml. let main () = Printf.printf "Hello, world - %d %s\n" (Array.length Sys.argv) Sys.argv.(0) ;; main () However, this code just works fine with ocaml/ocamlc/ocmalopt. Printf.

Delete comments generated by cpp

I use #include ".../frontend/tokens.mll" in lexer.mll, and then cpp -C -P frontend/lexer.mll -o frontend/lexer_new.mll to generate lexer_new.mll. That worked until I upgraded my ubuntu from 12.04 to 14.04 yesterday. The compilation gives an erro

OCaml Optional Argument

How can I write a function in OCaml in which one or more argument are optional? let foo x y z = if(x+y > z) then true else false;; If foo do not receive the z argument it uses 0 as z. foo 3 3 2 -> true foo 3 3 10 -> false foo 2 1 -> true Is th

Can F # units of measure be implemented in OCaml?

F# has a units of measure capability (there's more detail in this research paper). [<Measure>] type unit-name [ = measure ] This allows units to be defined such as: type [<Measure>] USD type [<Measure>] EUR And code to be written as: let

A sequence of optional grammar rules with menhir

I would like to implement the following grammar in OCaml using Menhir parser. There should be four different statement coming each after another, however, any three of them can be missing. So any program contains at least one of these statements, but

OCaml syntax error with let & hellip; in

I have a quite simple issue I think, but no way to figure out what's going wrong. I want to open a file and try to failwith a custom message if the file don't exist or something else. Here my code (sorry for french comment): if (argc = 1) then aide (

string_dec and string in the Ocaml library

I have file: extracted from String.v (It is from Coq library) : is a string library of Ocaml After extracted my test file from Coq to Ocaml, I want to used in the library of Ocaml, so I write an replace command to repla

How to manage a list of polymorphic variants?

Let two variant types : type typeA = | A1 | A2 ;; type typeB = | B1 of typeA | B2 of typeA ;; and type-checking functions : let isA1 = function A1 -> true | _ -> false;; let isA2 = function A2 -> true | _ -> false;; let isB1 = function B1 e -&

Define a tree + a pointer to its subtree in ocaml

How to define a tree + a pointer to its subtree in OCaml such that adding leaves in this subtree takes constant time?If you want to use purely functional representation, zippers -- suggested by nlucaroni -- are indeed the good solution to represent a

Type relationship between two modules built by functors

I have defined several signatures and modules as follows: module type MATRIX = sig type 'a t val init: 'a -> 'a t end module type MMM = sig type 'a t end module type AMATRIX = sig include MATRIX module Mmm : MMM module Matrix: MATRIX val mmm_of_amatr

How to plot & ldquo; failwith & rdquo; error in Emacs?

I am writing OCaml under Emacs. I have already configured Emacs so that Meta-x compile and make -k gives warnings with hyperlink. But for errors raised by failwith, it can not give a hyperlink, for instance: analyzing (ZONE)... Fatal error: exception

Is the execution of the add procedure O (n)?

For example, in OCaml when you are appending an item to a list of length n. [email protected][mylist] Yes, the runtime of @ in OCaml is O(n) (where n is the length of the left operand). Generally appending to the end of an immutable singly linked list (or an immuta

What's the easiest way to add an item at the end of the list?

As:: : 'a -> 'a list -> 'a list is used to add an element to the begin of a list, Could anyone tell me if there is a function to add an element to the end of a list? If not, I guess List.rev (element::(List.rev list)) is the most straightforward way

Learn / use ML. Which system should I use?

I want to learn and use ML but there are many compilers out there. I need: speed low memory usage threading mutable arrays and record types continuations ready for production code easy ffi up to date ... helpful libraries portable to some degree I do

openGL graphics capture in a video

I have written an openGL application and would like to produce a video of the graphics shown on the Glut window. Do you know how to do it? From a previous question at SO, I know that one possible solution is to use glReadPixels to get the frames that

Define exceptions with tuple as argument

I'm trying to define an exception in OCaml that accepts a tuple pair of lists as an argument. However, this situation doesn't work? # exception Foo of string list * string list;; exception Foo of string list * string list # let bar = (["a"], [&q

Mutable data in OCaml

I've created a mutable data structure in OCaml, however when I go to access it, it gives a weird error, Here is my code type vector = {a:float;b:float};; type vec_store = {mutable seq:vector array;mutable size:int};; let max_seq_length = ref 200;; ex

to run ocaml on Mac OS X gives a bus error

I've just installed Ocaml on Mac OS X, and when I run the ocaml program I get a "Bus Error" with no other clues to what might be going on. Can anyone offer suggestions on where to go from here? EDIT: I installed via the package: http://caml.inri