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

ocaml bitstring within a script

In ocaml toplevel, I can use "bitstring" package by typing the following commands: #use "topfind";; #camlp4o;; #require "bitstring.syntax";; let data = 0l;; let bits = BITSTRING { data : 32 };; However, if I create an OCaml script, e.g., foo.ml…
4
votes
2 answers

Picking which ocaml module to use with command line parameter

In my code I've module M = Implementation1 and then I reference M, instead of Implementation1. The problem is, I've to recompile my program to change Implementation1 to Implementation2. I'd like to control which implementation to use from with a…
pbp
  • 1,461
  • 17
  • 28
4
votes
2 answers

Does OCaml have fusion laws

Recently I am reading some functional programming books involving Haskell. It seems Haskell quite fancies “modular programs”, for example, f :: (Integer,Integer) -> Integer f = sum . map sq . filter . odd . between even though the same function…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
2 answers

Writing and reading to a memory mapped file in OCaml

I am experimenting in OCaml to see how I can read/write a numerical array to/from a memory mapped file. I think I'll need to use Bigarray but not sure how to write down a Bigarray array to a memory mapped file, and then read it back? I cannot seem…
4
votes
1 answer

ocaml doesn't load .ocamlinit in script mode

I find that when I run ocaml in terminal, ie, in interactive mode, it will load .ocamlinit. However, when I run ocaml test.ml, ie, in script mode, it doesn't load .ocamlinit file. This actually causes some trouble for me, since I have the following…
Wei Li
  • 471
  • 6
  • 14
4
votes
1 answer

Why can't the compiler match this function type?

I have an issue with the OCaml compiler I can't explain myself. The following code won't compile: open Postgresql let get_nodes conn = ignore (conn#exec "SELECT * FROM node_full") let () = let c = new connection () in ignore (get_nodes…
Fabian Pijcke
  • 2,920
  • 25
  • 29
4
votes
1 answer

Passing a string to a C library from OCaml using Ctypes and Foreign

I'm really new to OCaml, and wanted to try and do some work with pcap as a way of getting started, only, there doesn't seem to be a maintained library for it. After looking at the awesome Real World OCaml book, I figured I'd give writing a binding a…
PeterM
  • 2,534
  • 6
  • 31
  • 38
4
votes
3 answers

Weird thing of Array.create in OCaml

I'm a newbie at OCaml. And when I do some coding using array in Ocaml I come to a problem I can't understand. Here is the code: let a = Array.create 5 (Array.create 5 0); a.(0).(1) <- 1 I just want to assign 1 to a[0][1] but then things happened:…
KUN
  • 527
  • 4
  • 18
4
votes
1 answer

ocamlbuild: build plugin with options

I'm trying to write an ocamlbuild plugin (myocamlbuild.ml) that will use definitions from another file. I have a lot of definitions that I'd like to be used across several build plugins and I wanted put them in their own file. I tried running…
Gregory
  • 1,205
  • 10
  • 17
4
votes
1 answer

Use OUnit module in OCaml - Unbound module OUnit error

I'm trying to use OUnit with OCaml. The unit code source (unit.ml) is as follows: open OUnit let empty_list = [] let list_a = [1;2;3] let test_list_length _ = assert_equal 1 (List.length empty_list); assert_equal 3 (List.length list_a) (*…
prosseek
  • 182,215
  • 215
  • 566
  • 871
4
votes
3 answers

Using "ocamlfind" to make the OCaml compiler and toplevel find (project specific) libraries

I'm trying to use ocamlfind with both the OCaml compiler and toplevel. From what I understood, I need to place the required libraries in the _tags file at the root of my project, so that the ocamlfind tool will take care of loading them - allowing…
CharlieP
  • 993
  • 7
  • 19
4
votes
1 answer

Using opam from behind a firewall

I'm wondering what I need to setup so that opam will download packages through a proxy server if I'm behind a firewall.
aneccodeal
  • 8,531
  • 7
  • 45
  • 74
4
votes
2 answers

Application of Tail-Recursion in OCaml

I wrote this function in Ocaml but I want to write the same thing first applying tail-recursion and then fold_left. let rec check fore list = match list with | [] -> [] | h :: t -> if fore h then h :: check fore t …
emi
  • 2,830
  • 5
  • 31
  • 53
4
votes
1 answer

Pattern Matching performance in OCaml

Let's say I have such a type type 'a tree = Node of int * 'a * 'a tree The int part is the rank. Also I have a function let rank = function Node (r, _, _) -> r. Suppose in my real code, I have lots of places that need to access the rank of a node,…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
1 answer

ocaml style: parameterize programs

I have a OCaml program which modules have lots of functions that depend on a parameter, i.e. "dimension". This parameter is determined once at the beginning of a run of the code and stays constant until termination. My question is: how can I write…
Max Haslbeck
  • 151
  • 4