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
34
votes
15 answers

What is the OCaml idiom equivalent to Python's range function?

I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). What is the right OCaml idiom for this?
Pramod
  • 9,256
  • 4
  • 26
  • 27
34
votes
2 answers

What does "open!" mean?

I'm looking at an OCaml source file that begins with the following instruction: open! MiscParser I understand that open MiscParser means "open the MiscParser module", but I don't know what the exclamation mark means.
John Wickerson
  • 1,204
  • 12
  • 23
34
votes
6 answers

What's the easiest way to build an F# compiler that runs on the JVM and generates Java bytecode?

The current F# Compiler is written in F#, is open source and runs on .Net and Mono, allowing it to execute on many platforms including Windows, Mac and Linux. F#'s Code Quotations mechanism has been used to compile F# to JavaScript in projects like…
Phillip Trelford
  • 6,513
  • 25
  • 40
34
votes
4 answers

What's the difference between "equal (=)" and "identical (==)" in ocaml?

In OCaml, we have two kinds of equity comparisons: x = y and x == y, So what's exact the difference between them? Is that x = y in ocaml just like x.equals(y) in Java? and x == y just like x == y (comparing the address) in Java?
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
33
votes
3 answers

IDE for OCaml language

Is there any trusted OCaml IDE other than Camelia ? I would prefer an eclipse based IDE if existed.
becks
  • 2,656
  • 8
  • 35
  • 64
32
votes
1 answer

In OCaml, what type definition is this: 'a. unit -> 'a

Questions It was my first time I saw a type definition like 'a. unit -> 'a in Explicit polymorphic type in record Q1: What is this 'a. (notice the dot)? Q2: What is the terminology for this kind of type definition? If I do let f:'a. 'a list -> int…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
31
votes
2 answers

{X with value} in ocaml

I saw the following function call in Yacfe example: Visitor_c.vk_program { Visitor_c.default_visitor_c with Visitor_c.kexpr = (fun (k, bigf) exp -> match Ast_c.unwrap_expr exp with | Binary(e1, Logical (Eq), (((Constant(Int("0"))…
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
31
votes
4 answers

When choosing a functional programming language for use with LLVM, what are the trade-offs?

Let's assume for the moment that C++ is not a functional programming language. If you want to write a compiler using LLVM for the back-end, and you want to use a functional programming language and its bindings to LLVM to do your work, you have two…
james woodyatt
  • 2,170
  • 17
  • 17
30
votes
7 answers

How do you compute the difference between successive elements of a list of unknown size, functionally?

In a programming language that is purely functional (like Haskell) or where you are only using it in a functional way (eg clojure); suppose you have a list/seq/enumerable (of unknown size) of integers and you want to produce a new…
Pieter Breed
  • 5,579
  • 5
  • 44
  • 60
30
votes
1 answer

OCaml internals: Exceptions

I'm curious to know how exceptions are dealt with in OCaml runtime to make them so lightweight. Do they use setjmp/longjmp or do they return a special value in each function, and propagate it? It seems to me that longjmp would put a little strain on…
Waneck
  • 2,450
  • 1
  • 19
  • 31
30
votes
5 answers

Can good type systems distinguish between matrices in different bases?

My program (Hartree-Fock/iterative SCF) has two matrices F and F' which are really the same matrix expressed in two different bases. I just lost three hours of debugging time because I accidentally used F' instead of F. In C++, the type-checker…
Wang
  • 3,247
  • 1
  • 21
  • 33
30
votes
1 answer

Have "Brodal search trees" really been implemented for practical use?

Brodal et al. demonstrated in their ESA '06 paper the existence of a purely functional structure with logarithmic-time search, update and insertion, and constant-time merge. (Note I'm not talking about Brodal heaps, which are a different data…
xuq01
  • 588
  • 4
  • 17
30
votes
3 answers

Or-patterns in Haskell

In OCaml, I was used to writing code which looked like: let combine o1 o2 = match o1, o2 with | Valid, Invalid | Invalid, Valid -> Invalid | _ -> ... I didn't find a way to write or-patterns in Haskell and I really miss it. Does anyone…
30
votes
16 answers

What to learn? Lisp or OCaml or...?

I already have a few languages under my belt (in a rough order of expertise): Python, C, C++, PHP, Javascript, Haskell, Java, MIPS, x86 assembler. But it's been almost 2 years since I learned a new one, and I'm starting to get the itch. I have a few…
oggy
  • 1,855
  • 1
  • 13
  • 10
29
votes
3 answers

Why is OCaml's (+) not polymorphic?

I am an OCaml newbie. I like OCaml's speed but I don't fully understand its design. For example, I would like the + operator to be polymorphic to support integer, float and so on. Why do we need +.?
z_axis
  • 8,272
  • 7
  • 41
  • 61