Questions tagged [ocaml]

OCaml is a strict statically-typed functional programming language, focusing on expressiveness, correctness, and efficiency.

#OCaml

OCaml is a strict statically-typed functional programming language, focusing on expressivity, correctness, and efficiency. These qualities make it the language of choice for complex software and timely go-to-market strategies.

For more information visit, the official OCaml site.

##Resources for OCaml Developers

##Resources for learning OCaml

Stack Overflow OCaml FAQ

  1. Documentation
  1. Editor
  1. The core language
  1. Loops/recursion
  1. Tools
  1. Good practices

#See also:#

7516 questions
4
votes
2 answers

How can I map OCaml bytecode to its original source code location?

Is there some nice feature of the format or library for going from some part of the bytecode to the line of code it originally came from? This would obviously be useful for debugging and error messages. In particular, I'm looking at how hard it…
Tikhon Jelvis
  • 67,485
  • 18
  • 177
  • 214
4
votes
2 answers

Addition of element in a list of record (OCaml)

I have a list of record : list_clients = [{name = "c6"; number = 9}; {name = "c12"; number = 3}; {name = "c17"; number = 6};] I would like to simply make the sum of all the "number" of each record. What is the best way? I'm quite beginner with…
moumoute6919
  • 2,406
  • 1
  • 14
  • 17
4
votes
1 answer

Higher order types in OCaml (phantom types subtyping)

I'm using phantom types to emulate the state of a stack, as a wrapper module for ocaml-lua (Lua communicates with C/OCaml through a stack). Small code example: type 's t type empty type 's table type top val newstate : unit -> empty t (*…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
4
votes
2 answers

camlp4 syntax extension, parser error

I created a syntax extension that allow the definition of a type as type.yjson type_name { /* type_declaration */ } to be able to build a record value directly from a json file. The syntax extension insert a module and the function necessary to…
Marc Simon
  • 5,415
  • 1
  • 19
  • 21
4
votes
1 answer

Typing in ocaml methods

I was playing with method redefinition, and I found this silly example : class a = object method get (x : a) = x end class b = object inherit a method get (x : b) = x end I'm clearly specifying that I want the get method from the b…
bruce_ricard
  • 743
  • 1
  • 7
  • 15
4
votes
1 answer

F# much slower than Ocaml for handling complex keys like int*int*int in data structures

I have converted an Ocaml program into F#, and overall performance is the same as Ocaml. However, in order to get to this point, I had try replace exceptions by Option values. The program works a lot with list, maps etc that has int*int*int (=tuples…
mattias
  • 870
  • 5
  • 18
4
votes
3 answers

Reversing string in ocaml

I have this function for reversing strings in ocaml however it says that I have my types wrong. I am unsure as to why or what I can do :( Any tips on debugging would also be greatly appreciated! 28 let reverse s = 29 let rec helper i = 30 …
user2150929
4
votes
2 answers

Are match cases guaranteed to be tested by declaration order?

I have these two functions: let print_length = function | [] -> Printf.printf "The list is empty" | xs -> Printf.printf "The list has %d elements" (List.length xs) let print_length = function | [] -> Printf.printf "The list is empty" …
Jon Smark
  • 2,528
  • 24
  • 31
4
votes
3 answers

How do I define an int64 in OCaml?

let i = 32 will give me a int32. What if I want to define a int64?
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
1 answer

Modulo operation in C#, C and OCaml

I wanted to confirm that the modulo operation was an expensive operation so I tested this piece of code that checks if a given number is even: bool is_even(int n) { return (n & 1) == 0; } then this one: bool is_even_bis(int n) { return (n %…
Max
  • 3,453
  • 3
  • 32
  • 50
4
votes
1 answer

OCaml Error involving lists

I'm still fairly new to OCaml, and would like some assistance on optimizing code. I'm trying to multiply each element of a given list by the list's last element. Here's a snippet of my code: (* Find the last element of a function *) let rec lastE =…
4
votes
2 answers

Module: how to use union type on with?

I have a weird problem on my code, and I really don't know how to solve it: My code is the following: module type tGraphe = sig type node type arc end;; module One : tGraphe with type node=int and type arc=int = struct type…
Alexis Comte
  • 81
  • 1
  • 6
4
votes
3 answers

converting ocaml function to stream

Say I have the following block of OCaml code: let genblocks () = let blocks = ref [] in let rec loop depth block = let iter i = loop (depth - 1) (i :: block) in match depth with | 0 -> blocks := block :: !blocks | _ ->…
user2211937
  • 137
  • 1
  • 6
4
votes
2 answers

Ocamllex - What is the difference between characters ? ( # )

They've an operator with ocamllex which is the #: difference between two characters or character sets. Here, there is a notion I don't understand: it is the difference between characters. What does mean the difference between characters? So if…
afk
  • 563
  • 2
  • 5
  • 12
4
votes
3 answers

Initialize Array to Blank custom type OCAML

ive set up a custom data type type vector = {a:float;b:float}; and i want to Initialize an array of type vector but containing nothing, just an empty array of length x. the following let vecarr = Array.create !max_seq_length {a=0.0;b=0.0} makes…
Faisal Abid
  • 8,900
  • 14
  • 59
  • 91