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
22
votes
3 answers

OCaml print statements

Is it possible to put print statements for debugging/testing in blocks of code? For example, in Java you can use System.out.println("") in the middle of methods to check variables or other things. But in OCaml, would a command like print_string…
dxu
  • 459
  • 2
  • 5
  • 13
22
votes
4 answers

Extract nth element of a tuple

For a list, you can do pattern matching and iterate until the nth element, but for a tuple, how would you grab the nth element?
user3340037
  • 731
  • 2
  • 8
  • 23
22
votes
4 answers

OCaml cons (::) operator?

In OCaml, is there a way to refer to the cons operator by itself? For example, I can use (+) and ( * ) as int -> int -> int functions, but I cannot use (::) as a 'a -> 'a list -> 'a list function, as the following example show: # (+) 3 5;; - : int =…
Alan C
  • 413
  • 1
  • 3
  • 8
22
votes
2 answers

OCaml calling convention: is this an accurate summary?

I've been trying to find the OCaml calling convention so that I can manually interpret the stack traces that gdb can't parse. Unfortunately, it seems like nothing has ever been written down in English except for general observations. E.g., people…
Wang
  • 3,247
  • 1
  • 21
  • 33
21
votes
1 answer

Is it possible to use pipes in OCaml?

In F# I can't live without pipes (<| and |>) let console(dashboard : Dashboard ref) = let rec eat (command : string) = command.Split(' ','(',')') |> Seq.filter(fun s -> s.Length <> 0) |> fun C -> (Seq.head…
cnd
  • 32,616
  • 62
  • 183
  • 313
21
votes
4 answers

Looking for OCaml IDE

I like F# but sometimes I need something light and cross-platform and without .NET for sure. I tried to use OCamL many times but seems like I just can't start it. Installed IDEA, added OCamL plugin -> Doesn't work Installed eclipse ODT plugin ->…
cnd
  • 32,616
  • 62
  • 183
  • 313
21
votes
2 answers

"Error: unbound module" in OCaml

Here's a simple example of using the library Cohttp: open Lwt open Cohttp open Cohttp_lwt_unix let body = Client.get (Uri.of_string "http://www.reddit.com/") >>= fun (resp, body) -> let code = resp |> Response.status |> Code.code_of_status in …
Loku
  • 363
  • 1
  • 2
  • 7
21
votes
4 answers

Topological sort in OCaml

I'm trying to write topological sorting in ocaml, but I'm a beginner (in OCaml & graphs algorithms) and I can't do this by myself. It's easier for me to think about topological sorting in, for example, C++ (and there is a lot examples of topological…
justme
  • 211
  • 2
  • 5
21
votes
1 answer

How to use -thread compiler flag with ocamlbuild?

I am using Jane Street's async_core by adding package(async_core) in _tags. When I use ocamlbuild -use-ocamlfind -I src test/test_airport.native, it gives me the following error: camlfind ocamlopt -linkpkg -package async_core -package unix…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
21
votes
2 answers

OCaml: Set modules

I want to use OCaml to generates sets of data and make comparisons between them. I have seen the documentation for Module types like Set.OrderType, Set.Make, etc, but I can't figure out how to initialize a set or otherwise use them.
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
21
votes
2 answers

What is a principal type?

The OCaml compiler has a "-principal" option and the term "principal type" is sometimes mentioned in the mailing list. What exactly does it mean? The definition in Wikipedia is recursive, as it assumes the reader is already familiar with the…
Jon Smark
  • 2,528
  • 24
  • 31
20
votes
6 answers

How to set the default-directory of compilation in Emacs?

I am coding OCaml under Emacs, I have one makefile in the working folder, and several sub-folders containing .ml files. If I launch M-x compile and make works fine on a buffer of makefile, but does not work on a buffer of a .ml file, it gives me an…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
20
votes
4 answers

How can OCaml values be printed outside the toplevel?

The OCaml repl ("toplevel") has rich printing for any types, user-defined or otherwise. Is it possible to access this functionality outside the toplevel, rather than having to write an entirely custom set of value printers for one's own entire set…
jrk
  • 2,896
  • 1
  • 22
  • 35
20
votes
1 answer

When are refutation cases necessary in OCaml?

In the GADTs section of the "Language extensions" chapter of the official OCaml docs, refutation cases of the form _ -> . are introduced. However, I thought that pattern-matching was already exhaustive, so I'm not sure when a refutation case is…
Kevin Ji
  • 10,479
  • 4
  • 40
  • 63
20
votes
2 answers

OCaml variance (+'a, -'a) and invariance

After writing this piece of code module type TS = sig type +'a t end module T : TS = struct type 'a t = {info : 'a list} end I realised I needed info to be mutable. I wrote, then : module type TS = sig type +'a t end module T : TS =…
Lhooq
  • 4,281
  • 1
  • 18
  • 37