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

this pattern-matching is not exhaustive in OCaml

I am new in OCaml and I wrote some code to get the n element of a list let rec n_elem l n = match n with | 0 -> match l with | h::_ -> h | _ -> failwith "erorr with empty list" | _ -> match l with | h::t -> n_elem t (n-1) | _ ->…
lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
4
votes
1 answer

Returning a string from a C library to OCaml using CTypes and Foreign

I'm having some trouble mapping native OSX calls from OCaml where the c call expects a buffer and size to be passed in. I've worked through the examples in Real World OCaml on using CTypes and Foreign but they don't cover this case or at least it's…
lambda_foo
  • 182
  • 1
  • 7
4
votes
2 answers

Will shadowed binding be GCed?

Suppose I have this in an long run ml file: let l = [1;2;3] let l = [1;2;3;4] let _ = ... Will the first l = [1;2;3] be GCed sometime? What if the code is like this: let l = [1;2;3] let l = [1;2;3;4] let l = [1;2;3] let _ = ... There are…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
2 answers

OCaml: assert with the message

Another question again :P I'm not too sure whether I should post it here or on the OCaml mailing list, but I try SO first. I like assert statements. However, I find the error messages close to useless without an additional message (assertion…
George Karpenkov
  • 2,094
  • 1
  • 16
  • 36
4
votes
1 answer

Trying to dynamically load module with Dynlink

I'm trying to set up dynamic loading of OCaml modules using Dynlink. I wrote a very simple test program, but it's not working. This test program consists of two modules, Plug and Ext. Plug is the "main" module. It knows the filename of Ext and loads…
Nate C-K
  • 5,744
  • 2
  • 29
  • 45
4
votes
1 answer

OCaml: Stream.peek without consuming line?

I'm working on a program that iterates over an input file, with a variable number of 'programs', and ending in '0'. My function run works fine if I start it from the top of the file, but for some reason a line is consumed by peeking to see if the…
prichey
  • 75
  • 1
  • 7
4
votes
2 answers

How to examine a module/signature at ocaml top level?

Please: I would like to examine a module's signature; is there a function to do this? Just typing the name of the module doesn't work: # List ;; Error: Unbound constructor List In fact I want to do this for modules I define on the interactive top…
4
votes
2 answers

Library function to find difference between two lists - OCaml

Is there a library function to find List1 minus elements that appear in List2? I've been googling around and haven't found much. It doesn't seem too trivial to write it myself. I've written a function to remove a specific element from a list but…
Collin
  • 1,777
  • 4
  • 26
  • 42
4
votes
1 answer

When is CAMLparamX required?

I am writing an interface to a C-library using external declarations in OCaml. I used ctypes for testing but it involved a 100% overhead for fast calls (measured by a core_bench micro benchmark). The functions look like this: /* external _create_var…
choeger
  • 3,562
  • 20
  • 33
4
votes
1 answer

Building C++ code with ocamlbuild

I have found many guides on how to build .o files from C sources using ocamlbuild. These do not apply to C++ files, however, which ocamlbuild cannot build out of the box. I have tried writing a myocamlbuild.ml file (shown below after request)…
Nikos
  • 219
  • 1
  • 8
4
votes
1 answer

Can OCaml check tail recursion

Is there a way to get ocaml to tell me if a function implements a recursion using tail recursion? I don't mean reading the code. I mean getting ocaml to tell me, say like this: let x = tail_recursion f;;
user2926204
  • 111
  • 8
4
votes
3 answers

Can record field updates in OCaml be generalized?

I'm a very novice OCaml programmer so please forgive me if this is a stupid/obvious question. There's a lot to absorb and I may have missed this in the documentation. I have a base of code that's starting to look like this: let update_x p x = …
mbac32768
  • 11,453
  • 9
  • 34
  • 40
4
votes
3 answers

Checking if one element is equal to any element in a list in OCaml?

So what I have this list of ints, let's say it is let a = [14, 22, 47] in And what I want to do is check if some other identifier is equal to ANY of the elements in the list. I could obviously do: if (x = 14 || x = 22 || x = 47) then do…
sebster
  • 79
  • 2
  • 2
  • 8
4
votes
1 answer

Strange behaviour of default parameter value

I just start learning OCaml. And I have a question, why this code outputs different results every time I call him? let b () = Unix.time ();; let a ?(c = b ()) () = c;; a ();; ... a ();; I expected, that default value of c will be compute once.
glagola
  • 2,142
  • 3
  • 17
  • 20
4
votes
3 answers

Encoding versus using an existential type when encoded as a universal

I'm trying to better understand the nuances of encoding versus using an existential type after we transform it into a universal. In short, it appears to me that using an existential type is much easier than encoding one and I'll explain what that…
wyer33
  • 6,060
  • 4
  • 23
  • 53