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

Can I use the OCaml GC with the LLVM GC interface?

For my PHP LLVM backend I'd like to try out the OCaml GC. Is it possible to use it with LLVM? Especially: Is the OCaml GC decoupled enough to be used outside of the compiler? Is the LLVM GC interface mature enough to be used with the OCaml GC?
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
4
votes
2 answers

scanf not accepting first arg

The following code runs with no errors: let f x y = print_int (max x y); print_char ' '; print_int (x + y) in for i = 1 to Scanf.scanf "%d" (fun x -> x) do Scanf.scanf "\n%d %d" f; print_newline (); done; But when I declare a…
Redouane Red
  • 509
  • 1
  • 5
  • 13
4
votes
1 answer

Store global string in mutable variable using LLVM API

I'm making a compiler for a subset of PHP using LLVM and OCaml. Tutorials for string handling in LLVM is a bit lacking - at least I can't find any. This is the code I want to compile:
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
4
votes
1 answer

Why are int32s/int64s slower than ints?

I've just read this in the reference doc of the Int32 module: Performance notice: values of type int32 occupy more memory space than values of type int, and arithmetic operations on int32 are generally slower than those on int. Use int32 only…
Antoine
  • 1,782
  • 1
  • 14
  • 32
4
votes
1 answer

Ocamlyacc token not visible when performing semantic action

I am using ocamlyacc for a small parser which also performs some semantic actions on most parsing rules. I have defined a set of tokens in the beginning: %token T_plus %token T_minus %token T_int_const %left T_plus T_minus A parser rule…
VHarisop
  • 2,816
  • 1
  • 14
  • 28
4
votes
1 answer

How do the OCaml operators < and > work with non-integer types?

I'm curious how the greater than (>) and less than (<) operators work with types that are not int, float, or double in OCaml. For instance, I was able to discover that string "a" > "b" but is there some reference that lists the conventions for all…
cultau
  • 41
  • 1
  • 3
4
votes
3 answers

Mutually recursive datatypes

I'm attempting to create a pair of mutually recursive datatypes to represent a red-black tree in OCaml for a homework assignment. However, I'm very unfamiliar with the OCaml language so I'm having some syntactical issues. Here's what I have come up…
dmcqu314
  • 875
  • 11
  • 29
4
votes
1 answer

What is the workaround for OCaml: exception Invalid_argument("Random.int")?

I have this bit of code: let rec random_list = function | 0 -> [] | n -> ( Random.int max_int ) :: ( random_list (n-1) ) It compiles okay, but when I execute it, this error shows up: exception Invalid_argument("Random.int") What is the…
Stefan Ciprian Hotoleanu
  • 2,202
  • 1
  • 23
  • 30
4
votes
1 answer

what is OCaml's "ground coercion"?

OCaml sometimes gives a warning "this ground coercion is not principal". I think I understand the "not principal" part (the type inference gives at least two possible types, neither of which is a subtype of the other), but I don't know what the…
Wang
  • 3,247
  • 1
  • 21
  • 33
4
votes
3 answers

Equivalent of document.getElementsByClassName

I can't find a js_of_ocaml equivalent of document.getElementsByClassName. What is the canonical way to do? EDIT : I'm using js_of_ocaml v2.5.
Antoine
  • 1,782
  • 1
  • 14
  • 32
4
votes
1 answer

How do the binaries get embedded and separated between a bytecode executable and ocamlrun?

By binary I mean both bytecode and native code. I've built a program that only depends on the Standard Library, using ocamlbuild with a minimal set of flags: ocamlbuild -I … -use-ocamlfind -libs str program.byte It runs OK. Just for info, I use…
eruve
  • 661
  • 5
  • 12
4
votes
1 answer

What's the advantage using lazy evaluation in Queue data structure?

I'm reading Purely Functional Data Structures written by Chris Okasaki. In chapter 6, the book introduces lazy evaluation to us, I compared the two version (* https://github.com/mmottl/pure-fun/blob/master/chp5.ml#L47 *) module BatchedQueue : QUEUE…
alwaysday1
  • 1,683
  • 5
  • 20
  • 36
4
votes
1 answer

How can I add a onclick method using js_of_ocaml?

Hi suppose I have a button with id form-submit and I have the following function in my OCaml file: let () = let form_submit = Dom_html.getElementById "form-submit" in ... What is the right way to add a on_click method to the button? Should I…
Bob Fang
  • 6,963
  • 10
  • 39
  • 72
4
votes
3 answers

oasis picks up wrong ocamlbuild

I try to compile an Ocaml project with an Ocaml version provided by Opam. My ocamlbuild, ocamlfind, and oasis seem OK : /Users/fred/.opam/4.02.1/bin/ocamlbuild dhcp-182-73:compil fred$ which…
Godev
  • 316
  • 1
  • 4
  • 12
4
votes
1 answer

Deploying self-contained native OCaml application

I need to deploy to Linux box a native OCaml application that depends on several dynamic libraries. The idea is to prepare self-contained package (no dependencies on OCaml, OPAM etc.) that contains all stuff, and can be installed on hypothetically…
Stas
  • 11,571
  • 9
  • 40
  • 58