Skip to main content
4 votes
2 answers
689 views

I haven't found details about window closing detection in the Graphics documentation. How detect it so I can trigger an action on closing ? Thank you.
124 votes
5 answers
34k views

Haven't seen this "feature" anywhere else. I know that the 32nd bit is used for garbage collection. But why is it that way only for ints and not for the other basic types?
35 votes
17 answers
24k views

I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). What is the right OCaml idiom for this?
38 votes
11 answers
135k views

My input number is an int. But the input number must be in a range from -2055 to 2055 and I want to check this by using regular expression. So is there anyway to write a regular expression to check ...
1 vote
1 answer
168 views

I started using this pattern to obviate the need to repeat the complex type everywhere. Now I don't have many repetitions and the idea works. module type RadixNode = sig type 'a t end module ...
3 votes
1 answer
87 views

I'm trying to port an open source existing ocaml app from Makefiles to dune. The application includes some C and C++ stubs. I tried to add a test.c file in a library like this: (library (name cdk) ...
9 votes
2 answers
42k views

The modulo function in OCaml mod return results different when compared with the modulo operator in python. OCaml: # -1 mod 4 - : int = -1 Python: >>> -1 % 4 3 Why are the result different?...
1 vote
3 answers
2k views

I would like to make this functions recursive but I don't know where to start. let rec rlist r n = if n < 1 then [] else Random.int r :: rlist r (n-1);; let rec divide = function h1::...
13 votes
2 answers
4k views

I've searched around for the concept of GADT in OCaml, why we need it and when to use it, etc. I understand GADT is not only in OCaml but a more general term. I've found What are GADTs? http://...
5 votes
2 answers
1k views

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 ...
6 votes
3 answers
2k views

Its possible to create infinite, circular lists using let rec, without needing to resort to mutable references: let rec xs = 1 :: 0 :: xs ;; But can I use this same technique to write a function that ...
1 vote
1 answer
94 views

I am making a simple program that sums all the numbers to n. I am curious why I get a stack overflow when I don't use parentheses on n-1 and I don't when I use them. let rec summing n= if n=0 then ...
3 votes
2 answers
116 views

I was creating a simple concat, and thought that this might work. (** [foldl fun init lst] the [fun] gets applied, left to right: {[foldl fun init [e1;e2;e3;e4] -> fun e4 (fun e3 (fun e2 (fun e1 ...
5 votes
1 answer
1k views

According to AVL tree wiki The balance factor is calculated as follows: balanceFactor = height(left-subtree) - height(right-subtree). For each node checked, if the balance factor remains −1, 0, or +...
0 votes
1 answer
85 views

I use OCaml/Dream to create a simple HTML form (No sensitive data at all). let form_page request = let _csrf_token = Dream.csrf_token request in Dream.html (Printf.sprintf {| <form action="/...

15 30 50 per page
1
2 3 4 5
511