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

Unable to use s-expressions

I'm following Real World OCaml to get started with the language, and, at one point, I am to make use of s-expressions in a module signature. Here's my mli file: open Core.Std (** Configuration type for query handlers *) type config with sexp (**…
Richard-Degenne
  • 2,892
  • 2
  • 26
  • 43
4
votes
1 answer

ocaml class with method accepting derived classes

Consider the following code: module Proxy = struct type 'a t end class qObject proxy = object(self : 'self) method proxy : 'self Proxy.t = proxy end class qWidget proxy = object(self : 'self) inherit qObject proxy method add : qWidget ->…
Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42
4
votes
6 answers

First and last element of list OCaml

I am trying to get first and last element of the list in OCaml. I expect that my function will be like 'a list -> 'a * 'a What I am trying to do is let lista = [1;2;3;4;6;0];; let rec first_last myList = match myList with [x] ->…
miechooy
  • 3,178
  • 12
  • 34
  • 59
4
votes
1 answer

Ambiguous guarded pattern

The future 4.03 release of OCaml has added a new warning, 57, to prevent ambiguous guarded pattern. Namely, the issue is that on an or-pattern with a when clause, if the first part of the or-pat matches, but the when evaluates to false, the complete…
Virgile
  • 9,724
  • 18
  • 42
4
votes
1 answer

OCaml shared lib for another shared lib

I am exploring some adventurous ideas. TL:DR; gnumake is able to use loadable modules, I am trying to use that C barrier to use OCaml but have trouble with the OCaml runtime initializing. I have this OCaml code: (* This is speak_ocaml.ml *) let…
user1971598
4
votes
2 answers

label ~f in OCaml

I am working in OCaml, the environment that I use is Eclipe Mars. And when I try using List.iter [1.;3.;2.;-7.;4.;5.] ~f:(fun x -> update rsum x);; it gives an error saying that Error: The function applied to this argument has type 'a list ->…
4
votes
2 answers

ocaml, Functors : dependency injection

In Real World Ocaml Chapter 9 which is about functors : Dependency injection Makes the implementations of some components of a system swappable. This is particularly useful when you want to mock up parts of your system for testing and simulation…
Pierre G.
  • 4,346
  • 1
  • 12
  • 25
4
votes
2 answers

How can I constrain an OCaml integer type to a range of integers?

Reading the Real World OCaml book I came across the following type declaration (Chapter 6: Variants): # type color = | Basic of basic_color * weight (* basic colors, regular and bold *) | RGB of int * int * int (* 6x6x6 color cube *) …
Ivan Uemlianin
  • 953
  • 7
  • 21
4
votes
3 answers

Does "pure OCaml" equate "purely functional" in the literature and custom?

My understanding is that "Pure OCaml" means everything that is standard in OCaml, including its non "purely" functional features, whereas "pure functional" means the usual attributes: no side effects, no exception handling, etc. In that sense, "pure…
4
votes
2 answers

OCaml functions passing in one less argument

I'm looking at solutions for a homework and the code implements an OCaml function that takes in two arguments but when its called, it's only passed one argument. let rec func2 r x = match r with | [] -> [] | (nt,rhs)::t -> if nt = x then…
cheng
  • 1,264
  • 2
  • 18
  • 41
4
votes
2 answers

OCaml function with data type tree

We are give a tree that contains two types of elements. It is defined with the following data-structure. type ( 'a , 'b ) tree = Empty | Vertexa of 'a * ( 'a , 'b ) tree list | Vertexb of 'b * ( 'a , 'b ) tree list Write a function split:…
4
votes
1 answer

Automatically Generate difference pp for recursive data structures

The OUnit framework has a function assert_equal which can (among others) take an argument pp_diff that formats the difference of two inputs in a more readable way. Since data structures grow rather large in real world applications, this seems quite…
choeger
  • 3,562
  • 20
  • 33
4
votes
1 answer

referencing a module type signature

I'm trying to reference a type in a module signature to build another type. module type Cipher = sig type local_t type remote_t val local_create : unit -> local_t val local_sign : local_t -> Cstruct.t -> Cstruct.t val remote_create :…
njb
  • 93
  • 8
4
votes
2 answers

OCaml, extends a program a la Emacs

I love OCaml, I'm waiting for my copy of Real World OCaml ! I am a beginner OCaml programmer, just know the functionnal part, a little imperative, but not much about modules, functors, objects, etc... For sort of an interpreter project, I made sort…
4
votes
3 answers

How to find index of an Array element in OCaml

I am trying to find the index of an integer array element in ocaml. How to do this recursively. Example code:let a = [|2; 3; 10|];; suppose I want to return the index of 3 in the array a. Any help appreciated. I am new to OCaml programming
sudheesh ks
  • 351
  • 1
  • 8
  • 15