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
4
votes
2 answers

OCAML how to find the next element of the variant

I have -> type week = MON | TUE | WED...... I want to create the function tomorrow which return the next day! For example , if I call "tomorrow MON", the function will return TUE.
4
votes
1 answer

Mutable fields of records with multiple files

I'm working with multiple files, and i have a problem with one mutable field. In file1.ml, i declared: type mytype = { mutable numbers : int list; } So, in file2.ml, i have elements of type mytype. But, when i'm trying to…
4
votes
1 answer

use first-class module in OCaml

module type Arity = sig val arity : nat (* in my real code it has another type *) end module S = functor (A : Arity) -> struct let check = ... end I would like to use the function check inside the functor S without implement signature…
Quyen
  • 1,363
  • 1
  • 11
  • 21
4
votes
1 answer

Switch environment in OPAM

Is this possible to have several development environments, which share the same compiler? Actually, I want to use 4.00.1+short-types compiler with different set of installed packages, and the possibility to easily switch between these environments.…
Stas
  • 11,571
  • 9
  • 40
  • 58
4
votes
2 answers

Nested pattern matching in Ocaml

I want to write a function in Ocaml that given a list of quadruples and a quadruple (x,y,z,f), returns a list of that contains the tuples (x',y',z',g) such that x = x' or y=y' or z = z' (these are integers). Here is my first attempt let rec…
Amin
  • 251
  • 2
  • 15
4
votes
1 answer

Installed ocamlfind (findlib), but never can find any extra package in Mac

Just got a new Mac, Mountain Lion and I wish to make all ocaml related stuff set up. I used the following commands: opam switch 4.00.1 opam install findlib opam install batteries All are installed successfully without errors. But I can't use…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
2 answers

OCaml - compiling a program as a library

I have an OCaml program(with a main method - it generates an executable) and I want to use it as a library. I was compiling my program like this: ocamlc -I someDir -g -unsafe lotsOfCmoFiles -o outputFile and the program works fine. Now I'm removing…
sinan
  • 6,809
  • 6
  • 38
  • 67
4
votes
3 answers

Is anyone use SML or OCaml for building real world GUI?

After looking at some OCaml graphics related projects it seems that no one using it for building GUI. why ? is there any modern alternatives to those outdated libraries ?
Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
4
votes
3 answers

OCaml: Permutation of every value in two sets? (how to translate this from Java)

I have two sets, returned by Set.Make(t). I would like to generate every possible combination of the values in the two. How can I do this? This works to generate some pairs, but not all: List.combine (IntSet.elements odp) (IntSet.elements ftw) This…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
4
votes
3 answers

Does the OCaml compiler support true module aliasing?

I created a new module which is just a shorter alias for a module with a very long name: module M = ModuleWithLongName I'm in a situation where the size of the final executable matters. Is the above construct handled sanely by the compiler (i.e. M…
Jon Smark
  • 2,528
  • 24
  • 31
4
votes
3 answers

Are there other ways to deconstruct option types in OCaml?

OCaml's option type is really useful in cases where you have functions that might not return anything. But when I use this in many places, I find it cumbersome to handle the Some case and the None case all the time in a match ... with. For…
Jason Yeo
  • 3,602
  • 3
  • 30
  • 38
4
votes
2 answers

OCaml Invalid Argument("equal:abstract value")

It seems that I can't assign an abstract value to a ref and I'm not sure what to do. open Big_int let largest = ref zero_big_int;; let depth = ref zero_big_int;; let rec big i = (add_int_big_int i zero_big_int) and collatz = fun num depth -> …
drellem
  • 43
  • 3
4
votes
2 answers

Which way of these two pattern matching is more preferred?

I'm just curious, these two functions would do the same thing. But which one should I use? let f a = match a with b -> a;; let f a = match a with b -> b;; Or it just depends on your preference? I feel the second one would…
4
votes
2 answers

OCaml: Tree functions

Are there any modules or functions for dealing with trees? I have a type that looks like this: type t = Leaf of string (* todo: replace with 'a *) | Node of string * t list I'm struggling to do insertion, removal of subtrees, etc. I've used…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
4
votes
2 answers

What's the correct way to write this in OCaml?

type t = MyInt of int | MyFloat of float | MyString of string let foo printerf = function | MyInt i -> printerf string_of_int i | MyFloat x -> printerf string_of_float x | MyString s -> printerf (fun x -> x) s It reports: Error: This…
new_perl
  • 7,345
  • 11
  • 42
  • 72