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 syntax error in function

I have to create a function which will display each element from a set of strings. I did the following: module S = Set.Make(String);; module P = Pervasives;; let write x = ( P.print_string("{"); let first = true; S.iter (fun str -> (if…
Andrew
  • 43
  • 1
  • 1
  • 3
4
votes
7 answers

Recursive functions in OCaml

I have a little problem: I want to solve this problem with OCaml, so I tried this -> -> let rec somme x = if ( nor (bool_of_int (x mod 3)) (bool_of_int (x mod 5))) then x + (somme x-1) else (somme x-1) ;; val somme : int -> int = -> somme…
unautre
  • 191
  • 3
  • 11
4
votes
1 answer

Does scala have shortcuts for functional objects?

I'm writing class in Scala and want to write some update methods that will return a modified version of the original object. I want the class to continue to be immutable of course. Of course I could do it by explicitly creating a new object of the…
aij
  • 5,903
  • 3
  • 37
  • 41
4
votes
4 answers

Does there exist a standard name for the following function?

It seems I'm using over and over a pattern that I would like to abstract as a function. The idea behind the pattern is that maybe I have something and if not I can try to produce it. Here is some OCaml code for the function I'm interested in naming,…
Abdallah
  • 335
  • 1
  • 7
4
votes
2 answers

How to extend Map.Make functor

I can write my own extension for List module of OCaml, by defining a file lib.ml and including List module: module List = struct include List (* remove l x returns the list l without the first element x found or *) (* returns l if no element…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
4
votes
1 answer

Preprocessing error in code comments

I got this error when compiling my code with corebuild: ~/project $ corebuild debug.byte ocamlfind ocamldep -syntax camlp4o -package bin_prot.syntax -package sexplib.syntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax -package core -modules…
Jason Yeo
  • 3,602
  • 3
  • 30
  • 38
4
votes
1 answer

How can I simplify this ocaml pattern-matching code?

I'm writing a simple little ocaml program that reads an algebraic statement in from a file, parses it into an AST using ocamllex/ocamlyacc, reduces it, and then prints it. The part where I'm reducing the expression seems a bit... ugly. Is there…
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
4
votes
2 answers

Using Batteries in .mly file with ocamlbuild

I have a project with OCaml .ml files and a Menhir .mly file. I use ocamlbuild to compile the project. My _tags file contains this single line: true: use_menhir, package(batteries) Everything works well, except when I want to use Batteries in the…
p4bl0
  • 3,846
  • 1
  • 22
  • 21
4
votes
2 answers

How do I make a type that uses Batteries' Dyn_array in OCaml?

For instance, suppose I want to make a type like this (using Dyn_array): type some_type = SomeConstructor of I'm a little bit lost on how to do this though. Could someone give me an example so I can wrap my head around…
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
4
votes
4 answers

nested sequences to branching/tree data structure

I'm not sure if this is an easy problem to solve and I am just missing something obvious, but I have been banging my head against it for sometime. I am trying to express tree divergence using lists. This is so I can easily specify my dataset easily…
thedajaw
  • 168
  • 5
4
votes
3 answers

Hashtable indexed on several fields

I'm currently programming an OCaml module defining a type corresponding to a CPU register. The interface of this module is the following : (* * Defines a type which represents a R3000 register. *) type t = | R0 …
Pierre Bourdon
  • 10,521
  • 4
  • 33
  • 27
4
votes
1 answer

Get the array index variable and its value in value analysis (Frama-C)

I want to query the value analysis plugin in Frama-C for instructions to get their value. For each array, it returns the value range of the whole array. For example, if the instruction is array[i] = 1;, I got result = {1} for array[i] from value…
user2544482
  • 157
  • 4
4
votes
2 answers

Get result into a string variable in OCaml

I have this function working which prints out the value in an offsetmap: let pretty_offsetmap_original lv fmt offsetmap = begin match offsetmap with | None -> Format.fprintf fmt "" | Some off -> let typ = Some (typeOfLval lv) …
user2544482
  • 157
  • 4
4
votes
1 answer

How to make something lwt supported?

I am trying to understand the term lwt supported. So assume I have a piece of code which connect a database and write some data: Db.write conn data. It has nothing to do with lwt yet and each write will cost 10 sec. Now, I would like to use lwt.…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
1 answer

Permit side effect of a function

I have defined a module Comp whose operations are quite costly. In most of the cases, for a value of type Comp.t, a value of type int can be calculated, which can be used to accelarate many operations. So I define a type x as follows which…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292