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

Subtyping and Module Inclusion in OCaml

Suppose I have the following setup module type FOO = sig type f val do_foo : f end module type BAR = sig type b val do_bar : b end module type FOOANDBAR = sig include FOO include BAR end Now I want to (in a nice way, aka, without…
Joseph Victor
  • 819
  • 6
  • 16
4
votes
2 answers

load|use|require a library object file within an Ocaml source file

The Ocaml manual contains an exercise (here) in which library object files are loaded in the toplevel loop (the ocaml interactive interpreter) in the following way: #load "dynlink.cma";; #load "camlp4o.cma";; I'm trying to replicate the subsequent…
voutasaurus
  • 2,968
  • 2
  • 24
  • 37
4
votes
3 answers

What is the correct and smooth way to write a OCaml function?

I am learning Jason Hickey's Introduction to Objective Caml. After I learned Chapter 3, I seem to understand how the let and fun work. But still, I have troubles to write my own fun. Here is an example problem I am facing. Write a function sum…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
1 answer

Is this OCaml function composition operator definition/expression correct?

let (++) f g x = f (g x) in let f x = x + 1 in let g x = x * 2 in (f++g) 1;; Is the above expression correct? It seems to me that the above code should be just like defining f++g x = 2 * x + 1. Am I correct?
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
2 answers

How to understand the "body of the let"?

I am learning Jason Hickey's Introduction to Objective Caml. Just have a question about the expression thing. So it says: Definitions using let can also be nested using the in form. let identifier = expression1 in expression2 The expression…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
4
votes
2 answers

Trie data structure in OCaml

I am trying to build a trie in OCaml: type ('a, 'b) trie = Nil | Cons of 'a * 'b option * ('a, 'b) trie list;; (* find place to insert key in a list of tries *) let rec findInsert key x = match x with [] -> Nil | x::xs -> let Cons(k,…
Ihmahr
  • 1,110
  • 1
  • 16
  • 25
4
votes
2 answers

Linux Terminal Characters Show Up as Symbols Rather Than As Typed On Keyboard

I am using Ocaml from a Linux terminal. Sometimes it gets stuck in a weird mode where it does not respond to my keyboard as expected. For example, if I press the arrows up, down, right, and left, it generates ^[[A^[[B^[[C^[[D in input.…
user2174
  • 41
  • 1
4
votes
2 answers

OCaml parsing function

This is a function from a parser module. I have trouble understanding one line of code let rec e1 tokens = match tokens with Tokenizer.IfTok :: tokens1 -> let (testAST, tokens2) = e1 tokens1 in (match tokens2 with …
otchkcom
  • 287
  • 6
  • 13
4
votes
2 answers

Bindings and introspection for OCaml library

I want to write an OCaml library which will be used by other programing languages like C or even python. I not sure it's even feasible, and i guess i need to drop some type safety and add runtime checks to the interface for dynamically typed…
Enjolras
  • 371
  • 2
  • 8
4
votes
2 answers

FP homework. Is it possible to define a function using nested pattern matching instead of auxiliary function?

I am solving the Programming assinment for Harvard CS 51 programming course in ocaml. The problem is to define a function that can compress a list of chars to list of pairs where each pair contains a number of consequent occurencies of the character…
4
votes
1 answer

OCaml used in demonstrations?

I'm looking for examples of usages in OCaml to demonstrate simple properties or theorems. An example may be, given an ocaml definition of binary trees, demonstrate that the maximum number of nodes is 2^(h+1)-1. I have founds such kind of examples…
Fabio Varesano
  • 459
  • 6
  • 13
4
votes
1 answer

ocaml type constructor arguments

I defined an AVL tree as such, with 'a -> 'a -> int being the comparison function type 'a t = Empty of ('a -> 'a -> int) | Node of 'a * 'a t * 'a t * ('a -> 'a -> int) I'm trying to use this AVL module to implement a priority queue in a separate…
Mike
  • 709
  • 7
  • 19
4
votes
2 answers

Recursive List Creation Function. Errors in type

I have an Ocaml function that is giving me errors. What I am trying to do: Recursively create a List of random numbers (0-2) of size "limit". Here's what I have: let rec carDoorNumbers = fun limit -> match limit with | [1] -> Random.int 3 | [] ->…
Joshua Soileau
  • 2,933
  • 9
  • 40
  • 51
4
votes
1 answer

ocamlmktop with oasis

I am having trouble adding adding a library to ocamlmktop. I have a directory com, with an object file com/com.cma. If I run ocamlmktop com.cma -o top within the com directory, then the resulting executable top seems to have the library; i.e, I can…
Samir Jindel
  • 163
  • 1
  • 4
4
votes
2 answers

OCaml binary compiled with profiling information

Given a binary file compiled with OCaml, is there a way to find out if it has been compiled with profiling information (either using ocamlcp/ocamloptp, or with gprof-specific data via ocamlopt -p)?
anol
  • 8,264
  • 3
  • 34
  • 78
1 2 3
99
100