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
16
votes
4 answers

In OCaml, what is the canonical way of matching against multiple arguments of a function?

You could pattern-match against multiple arguments of a function by creating a tuple and then destructuring it in a match expression: let f x y = match x, y with | pattern1 -> expr1 | ... Alternatively, if you don't need a curried function,…
Pteromys
  • 1,441
  • 2
  • 12
  • 29
16
votes
2 answers

Cast float to int in OCaml

How am I supposed to cast a float to an integer in OCaml? I know how to get a float from an int, but there doesn't seem to be an easy way to get an int from a float.
Swiss
  • 1,260
  • 2
  • 17
  • 29
16
votes
5 answers

Actor-based distributed concurrency libraries for Ocaml and other languages

Question Can anyone recommend a library for Ocaml that offers an actor-based concurrency model for distributed computing? Note here the "actor-based" and "distributed" - I'd like the actor-based model, but also I want seamless handling of…
MGwynne
  • 3,512
  • 1
  • 23
  • 35
16
votes
3 answers

Obj module documentation

Is there any documentation about the Obj module? I could only find a list of functions without any description... (BTW: I know these are low-level functions not meant to be generally used)
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
16
votes
1 answer

How to install a specific version of ocaml compiler with opam

How can I install a specific version of ocaml compiler (and compatible packages) using opam (or another package manger)? I took a quick look through the opam documentation, but I don't find a relevant information. I need ocaml compiler (preferably…
norio
  • 3,652
  • 3
  • 25
  • 33
16
votes
4 answers

OCaml: Is there a function with type 'a -> 'a other than the identity function?

This isn't a homework question, by the way. It got brought up in class but my teacher couldn't think of any. Thanks.
Octopain
  • 171
  • 1
  • 8
16
votes
1 answer

OCaml functors, Haskell type classes, and multiple derivation

It is well-known that OCaml has a parametric polymorphism and this leads to some limitations. Haskell, through its type classes, offers an ad hoc polymorphism, which is, obviously, very convenient in several situations. It is also well-known that…
Samuele Giraudo
  • 409
  • 2
  • 14
16
votes
4 answers

The difference of the function keyword and match with in OCaml

I'm currently learning OCaml today I came up to this piece of code. let rec tree_to_list acc = function | Leaf x -> x::acc | Node (t1,t2) -> tree_to_list (tree_to_list acc t2) t1 As far as I understand this function does the same than this…
Colin G.D.
  • 351
  • 1
  • 3
  • 9
16
votes
1 answer

Unexpected results with OCaml !=

From what I can tell, = and != is supposed to work on strings in OCaml. I'm seeing strange results though which I would like to understand better. When I compare two strings with = I get the results I expect: # "steve" = "steve";; - : bool = true #…
Steve Rowe
  • 19,411
  • 9
  • 51
  • 82
16
votes
5 answers

How do I do automatic data serialization of data objects?

One of the huge benefits in languages that have some sort of reflection/introspecition is that objects can be automatically constructed from a variety of sources. For example, in Java I can use the same objects for persisting to a db (with…
Adam Gent
  • 47,843
  • 23
  • 153
  • 203
16
votes
2 answers

"as" keyword in OCaml

In the answers for the tutorials for OCaml available at this site, some of the solutions, including the one for eliminating consecutive duplicates of list elements, is written as such: let rec compress = function | a :: (b :: _ as t) -> if a = b…
Vincent Tjeng
  • 693
  • 8
  • 25
16
votes
2 answers

"Error: The function applied to this argument has type ..." when using named parameters

I'm currently working through "Real Word OCaml", and one of the basic examples with named / labeled parameters doesn't seem to work (using utop 4.01.0): let languages = ["OCaml"; "Perl"; "C"];; List.map ~f:String.length languages;; Produces: Error:…
Frank Schmitt
  • 30,195
  • 12
  • 73
  • 107
16
votes
3 answers

ocamlyacc parse error: what token?

I'm using ocamlyacc and ocamllex. I have an error production in my grammar that signals a custom exception. So far, I can get it to report the error position: | error { raise (Parse_failure (string_of_position (symbol_start_pos ()))) } But, I…
Arjun Guha
  • 486
  • 4
  • 11
16
votes
2 answers

Choosing between continuation passing style and memoization

While writing up examples for memoization and continuation passing style (CPS) functions in a functional language, I ended up using the Fibonacci example for both. However, Fibonacci doesn't really benefit from CPS, as the loop still has to run…
Abel
  • 56,041
  • 24
  • 146
  • 247
15
votes
3 answers

Statically "extend" a record-ish data type without indirection hassle

I am currently working with a three-level process for which I need some information to flow being accessed and updated. The information is also three-leveled, in such a way that a process at one level may need to access/update information at its…
Ptival
  • 9,167
  • 36
  • 53