Questions tagged [ocaml]
OCaml is a strict statically-typed functional programming language, focusing on expressiveness, correctness, and efficiency.
ocaml
7,640
questions
0
votes
0
answers
30
views
menhir `--interpret` for multiple files
I'm trying to use --interpret flag in Menhir to debug my parser, and I have separated my .mly files into tokens and grammar like this:
.
├── dune
├── lexer.mll
├── parser.mly
├── syntax.ml
└── tokens....
0
votes
2
answers
60
views
OCaml error during after build when accepting command line input
I'm currently trying to learn OCaml via the "Real World OCaml: Functional Programming for the Masses" textbook. I've reached the point of trying to build my first executable after playing ...
1
vote
3
answers
57
views
How to forward the arguments of a constructor to a function in OCaml?
I have a type with constructors which take many arguments. When pattern matching on a constructor of this type, I would like to forward the arguments as a pack (maybe a tuple?), without having to ...
0
votes
0
answers
44
views
How can I run inline unit tests in ocamldebug?
With the Dune buildsystem, it is easy to output a bytecode file for an executable for use with ocamldebug. However, it isn't clear how to do the same with inline unit tests; the Dune docs say how to ...
0
votes
2
answers
44
views
Implementing functions in module types
I have the following module type:
module type Element = sig
type t
type mystruct = {x: int; y: int}
val (<) : t -> t -> bool
val string_of_element : t -> string
(* val (>) : t ...
2
votes
2
answers
51
views
How can OCaml dune test program find test input files?
── test
├── dune
├── test_program.ml
└── foo_files
├── foo_a
└── foo_b
How can test_program find the files under folder foo_files when run using dune test?
I can see that ...
2
votes
1
answer
77
views
Why I get error "The type variable 'a occurs inside 'a t" with enabled -rectypes flag
I would like to write catamorphism in OCaml for any endofunctor (in terms of types) as a functor (in terms of OCaml):
module type Functor = sig
type 'a t
(* ... *)
end
module Make(F : ...
0
votes
1
answer
69
views
Check type of variable within a pattern match in OCaml
How do I check the type of a variable within a pattern matching in OCaml, version I currently use is 4.13, that is available online.
I found this post: OCaml: Type Checking Objects
But it doesnt ...
0
votes
1
answer
66
views
ocaml Unbound value String.starts_with [closed]
I want to compile a simple program. Here is eyana.ml
let () =
Format.printf "%d\n" (List.length [7;8;9]);
if String.starts_with ~prefix:"Eyana" "Eyana est très jolie!&...
-1
votes
1
answer
47
views
How to use ocaml library set to make data structure archive?
I am using the functional approach to programming learn ocaml. I coded an example about graph.
code link here
In this case, I used a list to represent the an archive.
type comparison = Smaller | Equiv ...
3
votes
0
answers
84
views
Why does OCaml implement List.map with a special case for a singleton?
OCaml implements map over lists like so:
let[@tail_mod_cons] rec map f = function
[] -> []
| [a1] ->
let r1 = f a1 in
[r1]
| a1::a2::l ->
let r1 = f a1 in
let ...
0
votes
1
answer
53
views
Installing Opam and OCaml on Windows with WSL Ubuntu
I am trying to install OCaml on Windows using WSL.
I followed these instructions: Install WSL
So I opened a PowerShell and typed wsl --install
After having rebooted, I started the Windows Command ...
0
votes
2
answers
37
views
One file ocaml program with a signature, a module and a main function
I am still unable to install OCaml correctly on my Windows computer. That's why I use the online compiler from here and must program everything in one file!
I want to have a module with a signature ...
0
votes
2
answers
57
views
Compile a one file ocaml program with a module and a main method
I somehow can't install a working OCaml environment on my Windows computer. I want to use know the OCaml online compiler. Problem: I can only write one file there and put everything in that one file:
...
1
vote
1
answer
39
views
Disable autocomplete suggestion bar in utop
How can I disable the autocomplete suggestion bar in the utop OCaml toplevel?