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

typing recursive modules

In Leroy's paper on how recursive modules are typed in OCaml, it is written that modules are checked in an environment made of approximations of module types: module rec A = ... and B = ... and C = ... An environment {A -> approx(A); B ->…
15
votes
1 answer

What's the difference with or without backtick "`"?

type level = [ `Debug | `Info | `Warning | `Error] Can i remove the "`" here ? Sincerely!
z_axis
  • 8,272
  • 7
  • 41
  • 61
15
votes
4 answers

OCaml: Pattern matching vs If/else statements

So, I'm totally new to OCaml and am moving pretty slowly in getting my first functions implemented. One thing I'm having trouble understanding is when to use pattern matching abilities like let foo = [] -> true | _ -> false;; vs using the if…
15
votes
4 answers

Better to use "and" or "in" when chaining "let" statements?

I realize this is probably a silly question, but... If I'm chaining a bunch of let statements which do not need to know each other's values, is it better to use and or in? For example, which of these is preferable, if any: let a = "foo" and b =…
koschei
  • 819
  • 6
  • 13
15
votes
3 answers

Type of addition (+) in F#

I just learned that OCAML have to have a . postfix for doing float arithmetic. An example would be 3. +. 4. which equals 7. (float). However, F# handles float and integer arithmetic in the same way, so both 3 + 4 (int) and 3. + 4. (float) works. F#…
Lasse Espeholt
  • 17,622
  • 5
  • 63
  • 99
15
votes
2 answers

Can Haskell or OCAML handle sensitive data without leaking via garbage collection?

I would do something like this (pseudo code): 1. load sensitive encrypted data from file 2. decrypt the data 3. do something with the unencrypted data 4. override the data safely / securely (for example with random data) The time that the sensitive…
user573215
  • 4,679
  • 5
  • 22
  • 25
15
votes
1 answer

State monad in OCaml

I was trying to implement the state monad in OCaml (as an exercise). My implementation looks like this: module type MONAD_BUILDER = sig type 'a t val return : 'a -> 'a t val bind : 'a t -> ('a -> 'b t) -> 'b t end;; module MonadBuilder =…
Alex
  • 2,040
  • 2
  • 19
  • 29
15
votes
1 answer

Where is OCaml's alternative string syntax {|...|} documented?

OCaml's syntax for string literals let s = "..." is explained in the manual at the expected position: https://caml.inria.fr/pub/docs/manual-ocaml/lex.html#s:stringliteral However, OCaml has an alternative syntax for string literals which is…
vog
  • 23,517
  • 11
  • 59
  • 75
15
votes
2 answers

What's the difference between include, require and open in OCaml?

For example, include: include Ppx_core open: open Core.Std require: #require "compiler-libs.common" and use: #use "topfind"
Yixing Liu
  • 2,179
  • 1
  • 20
  • 36
15
votes
3 answers

How can I install OCaml with OPam on windows?

How can I install OCaml with OPam on windows?
pinkdolphin
  • 303
  • 1
  • 3
  • 7
15
votes
2 answers

How to define an infix (not symbolic aka not an operator) function in OCaml?

does OCaml support infix functions defined in plaintext ? arg1 `plus` arg2 = arg1 + arg2 thanks
desmogix
  • 217
  • 2
  • 8
15
votes
1 answer

Functors with multiple arguments in OCaml

I've the following situation: module type M = sig type s = ... end module Make(P: Something) : (M with type s = P.t) = struct type s = P.t ... end that works fine to generate modules of M type that use specific implementation of modules of…
Jack
  • 131,802
  • 30
  • 241
  • 343
15
votes
5 answers

Pattern Matching, F# vs Erlang

In Erlang, you are encouraged not to match patterns that you do not actually handle. For example: case (anint rem 10) of 1 -> {ok, 10} 9 -> {ok, 25} end; is a style that is encouraged, with other possible results resulting in a badmatch…
Muhammad Alkarouri
  • 23,884
  • 19
  • 66
  • 101
15
votes
1 answer

How to merge OCaml module types (signatures) defining the same type?

In OCaml, I have two module types defining a type t: module type Asig = sig type t val a : t end module type Bsig = sig type t val b : t end I want to automate the creation of a module type merging them. I want to create a module…
jacquev6
  • 620
  • 4
  • 18
15
votes
1 answer

What is the meaning of Warning 40: this record ... contains fields that are not visible in the current scope

Please consider the following code: module A = struct type r = { i : int; s: string } end module B = struct type r = { i : int; s : string } end let f (x : A.r) : B.r = match x with { i; s } -> { i = 2*i; s = "" } Two modules…
lambda.xy.x
  • 4,918
  • 24
  • 35