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

What's the difference (if any) between Standard ML's module system and OCaml module system?

My question is if there is any difference between Standard ML's module system and OCaml module system? Has OCaml all the support of functors , ascriptions etc... that SML has?
Dragno
  • 3,027
  • 1
  • 27
  • 41
42
votes
3 answers

Variants or Polymorphic variants?

I noticed that, among OCaml programmers I know, some of them always use polymorphic variants (variants that are not declared, prefixed with a backquote), while other ones never use polymorphic variants, and prefer variants declared in types. Except…
42
votes
5 answers

Redundancy in OCaml type declaration (ml/mli)

I'm trying to understand a specific thing about ocaml modules and their compilation: am I forced to redeclare types already declared in a .mli inside the specific .ml implementations? Just to give an example: (* foo.mli *) type foobar = Bool of bool…
Jack
  • 131,802
  • 30
  • 241
  • 343
41
votes
4 answers

What is the state of OCaml's parallelization abilities?

I'm interested in using OCaml for a project, however I'm not sure about where its parallelization capabilities are anymore. Is there a message passing ability in OCaml? Is OCaml able to efficiently use more than 1 CPU? Most of what I have read on…
Andrew Spott
  • 3,457
  • 8
  • 33
  • 59
41
votes
1 answer

Calling OCaml-wrapped ZeroMQ code from signal handler

I've written some OCaml bindings for CZMQ based on the guide at http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php, which seem to work pretty well. For example here's zstr_send: CAMLprim value caml_zstr_send(value socket_val, value…
user1494672
  • 504
  • 4
  • 10
40
votes
6 answers

Is there an infix function composition operator in OCaml?

Just a quick question. I'm wondering if there is a infix function composition operator in OCaml defined in the standard library (or in Jane Street's Core or in Batteries) like the (.) function in Haskell which saves us a lot parentheses since we…
tfboy
  • 947
  • 1
  • 10
  • 14
39
votes
2 answers

What are the pros and cons of Batteries and Core?

In the OCaml world at present there appear to be a number of competing extensions to the standard library, Batteries and Jane Street Core being the major ones as far as I can determine (I understand that ExtLib has been subsumed into Batteries?).…
Gaius
  • 2,556
  • 1
  • 24
  • 43
39
votes
11 answers

Using regular expressions to validate a numeric range

My input number is an int. But the input number must be in a range from -2055 to 2055 and I want to check this by using regular expression. So is there anyway to write a regular expression to check whether a number is in (-2055, 2055) or not ? It is…
Trung Nguyen
  • 459
  • 1
  • 5
  • 6
39
votes
5 answers

How do I get a stack trace in OCaml?

The Objective Caml language will only produce stack traces if you ask for them just right - what are the requirements for both bytecode and native code?
Thelema
  • 14,257
  • 6
  • 27
  • 35
38
votes
2 answers

OCaml - How do I convert int to string?

How do I convert an int to a string? Example: 1 to "1".
EBM
  • 1,067
  • 2
  • 11
  • 20
38
votes
1 answer

If SML.NET had functors why can't F#?

This question started out from My translating of "ML for the Working Programmer" (WorldCat) by L. C. PAULSON to F# which uses functors for the examples. Eventual desire to translate "Purely Functional Data Structures" (WorldCat) by Chris…
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
37
votes
3 answers

Algorithm for type checking ML-like pattern matching?

How do you determine whether a given pattern is "good", specifically whether it is exhaustive and non-overlapping, for ML-style programming languages? Suppose you have patterns like: match lst with x :: y :: [] -> ... [] -> ... or: match lst…
Tommy McGuire
  • 1,223
  • 13
  • 16
35
votes
3 answers

What are row types? Are they algebraic data types?

I often hear that F# lacks support for OCaml row types, that makes the language more powerful than F#. What are they? Are they algebraic data types, such as sum types (discriminated unions) or product types (tuples, records)? And is it possible to…
MiP
  • 5,846
  • 3
  • 26
  • 41
35
votes
1 answer

What are the benefits of OCaml as a programming language behind Hacklang and Flow?

Recently, Facebook announced Flow, a static type checker for JavaScript, which is implemented mainly in OCaml (https://code.facebook.com/posts/1505962329687926/flow-a-new-static-type-checker-for-javascript/). Hacklang (PHP with static type checker)…
Supasate
  • 1,564
  • 1
  • 16
  • 22
34
votes
3 answers

Tail recursive function to find depth of a tree in Ocaml

I have a type tree defined as follows type 'a tree = Leaf of 'a | Node of 'a * 'a tree * 'a tree ;; I have a function to find the depth of the tree as follows let rec depth = function | Leaf x -> 0 | Node(_,left,right) -> 1 + (max (depth…
ppaul74
  • 751
  • 1
  • 13
  • 21