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

How to implement mixins in OCaml

How to implement mixins in the OCaml module system. The closest I achieved is to use the following methodology, which I illustrate on a MixinFormat which adds usual output functions print, output and to_string on a mixin able to format. Assume that…
Adèle Blanc-Sec
  • 453
  • 2
  • 11
4
votes
1 answer

Location in syntax trees

When writing a parser, I want to remember the location of lexemes found, so that I can report useful error messages to the programmer, as in “if-less else on line 23” or ”unexpected character on line 45, character 6” or “variable not defined” or…
Adèle Blanc-Sec
  • 453
  • 2
  • 11
4
votes
1 answer

Visible refinement of class methods

consider the following small ocaml class hierarchy: class x = object method i = 0 end ;; class y = object method x = new x end ;; class x2 = object method i = 0 method j = 1 end ;; class z = object method x = new x2 inherit y end;; (* type error…
choeger
  • 3,562
  • 20
  • 33
4
votes
1 answer

mark_tag_used warning with OCaml 4.02.0

I'm just trying my code with OCaml 4.02 (using opam) and I get lots of warnings like this: File "_tags", line 14, characters 121-134: Warning: the tag "link(utils.o)" is not used in any flag declaration, so it will have no effect; it may be a…
Thomas Leonard
  • 7,068
  • 2
  • 36
  • 40
4
votes
3 answers

ocaml formatters and value restriction

EDIT: I'm sorry everyone, I thought my small examle was complete, turns out it's not. I made a new one that really should be! As soon as I use a formatter as parameter to Scanf or Printf functions the formatter type gets bound to a in- or…
Bladt
  • 303
  • 3
  • 11
4
votes
1 answer

Typechecker assertion failed on recursively-typed class

Consider the following small example: type 'r foo_t = 'r; ..> as 'r and 'r bar constraint 'r = 'r foo_t class c : object('r) constraint 'r = 'r foo_t method get : 'r bar option method set : 'r…
choeger
  • 3,562
  • 20
  • 33
4
votes
1 answer

ocaml debugger can't find core when run from emacs

I'm trying to use the ocaml debugger to display variables at runtime from emacs. When I use the middle mouse button, as suggested by this guide my system just pastes from the clipboard. When I try to explicitly use the display command on a variable,…
user3131124
  • 119
  • 5
4
votes
4 answers

Accepting only one variant of sum type as OCaml function parameter

I have a large sum type originating in existing code. Let's say it looks like this: type some_type = | Variant1 of int | Variant2 of int * string Although both Variant1 and Variant2 are used elsewhere, I have a specific function that only…
Computerish
  • 9,590
  • 7
  • 38
  • 49
4
votes
1 answer

About the minor / young heap of OCaml GC

I am reading about the GC, Chapter 21 in Real World OCaml, and have a few questions about the minor heap. So it says: The minor heap is a contiguous chunk of virtual memory that is usually a few megabytes in size so that it can be scanned…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
1 answer

Frama-C unbound module Z build error

Using Ubuntu 14.04, I downloaded the Neon Frama-C distribution, and installed the required tools: labgtk, sourceview, etc. I configured Frama-C no problem, but on building got: File "external/unz.ml", line 39, characters 10-19: Error: Unbound…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31
4
votes
2 answers

How to sum a list of float numbers in OCaml

I am puzzled with my code: let sum l = match l with | [] -> 0.0 | h::t -> h +. (sum t);; It should give me the sum of the numbers in the list. However when I check the code, I found the second code crashes when I use a list of length greater…
Bombyx mori
  • 288
  • 1
  • 3
  • 15
4
votes
1 answer

Can I use pa_monad to ensure η-expansion?

I am developing a library where several state monads are commonly mixed. What kind of state is mixed in is not known a-priori, but will likely be defined at the application level. Therefore, my solution is to develop one state monad that has an…
choeger
  • 3,562
  • 20
  • 33
4
votes
1 answer

Create sum type in C implementation of OCaml function

Let's say you had a type declaration: type foo = Bar | Baz of int How would you implement a C function to create a Baz? Let's say I declare it like this: external create_baz : int -> foo = "create_baz" Then I would need to fill out this…
brooks94
  • 3,836
  • 4
  • 30
  • 57
4
votes
1 answer

OCaml Increment mutable variable several times

I feel slightly ashamed for asking such a trivial question but here I go. I need a function to increment a globally defined mutable variable. let seed_index = ref 0;; let incr_seed() = seed_index := !seed_index + 1;; However, I can't get it…
user3075773
  • 139
  • 1
  • 5
4
votes
2 answers

S-expression Tree to Abstract Syntax Tree in OCaml

I'm implementing a symbolic language in OCaml and have been struggling to translate my s-expression tree into an abstract syntax tree. The s-expression tree is (* sexpr.mli *) type atom = | Atom_unit | Atom_int of int | Atom_sym of…