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
14
votes
1 answer

Dependent types in OCaml

There's a lot of information about dependent types in Haskell and Scala. For OCaml, not so much. Is anyone skilled enough to provide a coding example on how to achieve this in OCaml (if it's possible at all)? There is of course (the abandoned)…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
14
votes
1 answer

OCaml: higher kinded polymorphism (abstracting over modules?)

Let's say I have a list of options: let opts = [Some 1; None; Some 4] I'd like to convert these into an option of list, such that: If the list contains None, the result is None Otherwise, the various ints are collected. It's relatively…
Impredicative
  • 5,039
  • 1
  • 17
  • 43
14
votes
1 answer

OCaml: Default values for function arguments?

In PHP, default values for arguments can be set as follows: function odp(ftw = "OMG!!") { //... } Is there similar functionality in OCaml?
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
14
votes
3 answers

Sleeping less than a second in OCaml

The Unix.sleep function can suspend the program for whole seconds, but how can you suspend it for less than a second?
Matthew Piziak
  • 3,430
  • 4
  • 35
  • 49
14
votes
2 answers

OCaml Printf.sprintf

Why does this behavior occur? # Printf.sprintf ("Foo %d %s") 2 "bar";; - : string = "Foo 2 bar" # Printf.sprintf ("Foo %d" ^ " %s") 2 "bar";; Printf.sprintf ("Foo %d" ^ " %s") 2 "bar";; Error: This expression has type string but an expression was…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
13
votes
2 answers

OCaml Module : include AND open?

I'm fairly new with OCaml Module and I haven't managed to use my own module without combining both an "include" and an "open". I've tried to put the signature in a separate .mli file, without success. Below I'm indicated a minimum (not) working…
Loïc Février
  • 7,540
  • 8
  • 39
  • 51
13
votes
4 answers

OCaml functors :: counter-intuitive behaviour

I am experimenting with the module language of OCaml (3.12.1), defining functors and signatures for modules and so on, mostly following the examples from Chapter 2 of the OCaml manual and I've stumbled, by accident, on a situation where apparently…
Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331
13
votes
1 answer

ocaml toplevel module loading

I'm trying to load my modules in .cmo into the toplevel, I had tried: $ ocaml mymodule.cmo I got the toplevel prompt, but I couldn't refer to Mymodule I also tried the #load "mymodule.cmo" It did not complain but still can't refer to Mymodule I…
romerun
  • 2,161
  • 3
  • 18
  • 25
13
votes
1 answer

Functors in OCaml

I am having a bit of a problem with a functor (and it's resultant type). Below, I have a Set functor that uses an Ordered type. I actually used the set.ml that comes with OCaml for some guidance, but I seem to be doing everything ahem right. I…
nlucaroni
  • 47,556
  • 6
  • 64
  • 86
13
votes
2 answers

What is the difference between 'a and '_l?

What is the difference between 'a and '_l? I was looking at this error, and couldn't comprehend it: Error: This expression has type ('a -> float polynomial) list but an expression was expected of type float polynomial list derivlist: ('_l → float…
Zubeen Lalani
  • 331
  • 2
  • 10
13
votes
1 answer

OCaml ctypes idiomatic way to deal with out parameters

I'm writing OCaml wrappers for a few C functions that use the out-parameter idiom and return an error code. I've been wrapping them by allocating a C array on the OCaml side using Ctypes.allocate_n. And then copying the contents out into an OCaml…
Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65
13
votes
3 answers

How to write code in F# for what functors do in OCaml?

I have many programs written in OCaml, some of them use functors. Now, I am considering of writing and re-writing a part of code in F# (to benefit some advantages that OCaml does not have). One thing I am afraid of is to write code in F# for what…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
13
votes
3 answers

Merlin complains about a missing module in the same project

I am new to Ocaml and just setting up my dev environment with emacs, merlin and flycheck. Everything works more or less expected except one thing : merlin doesn't seem to be able recognise the dependencies between the modules in the same…
Roman Shestakov
  • 497
  • 5
  • 16
13
votes
3 answers

How does Ocaml decide precedence for user-defined operators?

I want nice operators for complex arithmetic to make my code more readable. Ocaml has a Complex module, so I just want to add operators that call those functions. The most intuitive way for me is to make a new complex operator from all of the usual…
forefinger
  • 3,767
  • 1
  • 22
  • 18
13
votes
2 answers

What does GADT offer that cannot be done with OOP and generics?

Are GADTs in functional languages equivalent to traditional OOP + generics, or there is a scenario where there are correctness constrants easily enforced by GADT but hard or impossible to achieve using Java or C#? For example, this "well-typed…
Alex
  • 1,184
  • 7
  • 15