Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Browsing all 518 articles
Browse latest View live

OCaml and Opam: unbound module Core

I'm trying to get an OCaml environment set up, and I've followed the instructions from appendix A of the Real World OCaml beta. I set up opam, and installed a version of OCaml with the command$ opam...

View Article


Getting "Unbound record field mid_x"

I am not understanding why I am getting this error: Unbound record field mid_x when running this code. What the function midpoint_segment is trying to do is find the midpoint of a given type segment...

View Article


Why this recursion example in ocaml doesn't work for negative number?

In the Think Ocaml book the author gave this example:let rec countdown n = if n <= 0 then ( print_string "Blastoff!"; print_newline()) else ( print_int n; print_newline(); countdown (n-1); ());;The...

View Article

OCaml with MSYS2 on Windows: Unbound module stdlib

I have just installed ocaml on MSYS2 with the commandpacman -S mingw-w64-x86_64-ocamlThen runningocaml -versiongives me the output 4.14.0I wrote my first program, which looks...

View Article

Compiling multifile projects in Ocaml, leading to Unbound Module error

ContextI am currently trying to learn the basics of OCaml (by doing the 2022 advent of code challenges). My aim is to get the basic down using only the OCaml standard library and writing my own...

View Article


Installing Dune with the help of Opam

I have somehow managed to install Opam on MSYS2 on Windows.When I open the MSYS2 MING64 (the blue one) shell and enteropam --versionit tells me that it is installed.When I runopam install dune, that...

View Article

OCaml equivalent of Python generators

The french Sécurité Sociale identification numbers end with a check code of two digits. I have verified that every possible common transcription error can be detected, and found some other kinds of...

View Article

Why does exiting Utop and reloading of modules not work?

When I start my utop interpreterand thensay #quit;;I get the answer Error: unbound value quitThe command#Topfind.reset();;doesn't recompile the ml-files, that I have changedI always need to kill the...

View Article


Can't understand the syntax in ocaml code

I have the following code:module Make_Set (Elt : EQ) : SET with type elt = Elt.t = struct type elt = Elt.t type t = elt list let empty = [] let rec is_element i set = match set with [] -> false | x...

View Article


How to read large files faster [closed]

I am writing a parser in OCaml and first I need a function to read the object file. I wrote the following function to read the contents of the target file and convert it to string output:let...

View Article

OCaml version in utop [closed]

When I use utop, the version of OCaml used is 4.05.0. I need to use a newer version (4.07.0 or higher).I have already installed a newer version (4.07.0), and I have configured the path variable so that...

View Article

How to write a function to count the number of elements in a list using a Map?

module IntMap = Map.Make(struct type t = int let compare = compare end)let rec count_with_map (il: int list) = match il with | [] -> [] | head :: tail -> match count_with_map tail with | (c, n)...

View Article

Module unavailable when compiling another file that uses it in OCaml

I have multiple compilation units in OCaml, one of which is causing a few problems. One compilation unit has two files foo_one.mli and foo_one.ml, these compile without any errors when using ocamlc....

View Article


OCaml functions on uncertain data types

I have a data type,type data = IntData of int list | FloatData of float listI want to write a function with signature map : data -> ('a -> 'a) -> data which will apply the given function to...

View Article

Can I define pattern synonyms in OCaml?

Haskell has PatternSynonyms which enables to simplify a complex pattern matching. An example is shown in that extension description page. That is, for Type below,data Type = App String [Type]with these...

View Article


Inverting chained maps?

A very common pattern in functional programming is to chain a series of calls to map on lists. A contrived, simple example:[1; 2; 3] |> List.map (fun x -> x + 1) |> List.map (fun x -> x *...

View Article

Using infix operator in the module in OCaml

I am trying to define a SCALAR signature with its own infix operator inmodule type SCALAR =sig type t (* type of scalar element *) val zero : t val one : t val (++) : t -> t -> t (* infix...

View Article


Do any OCaml compilers take advantage of the unspecified order of evaluation...

According to the OCaml manuallet pattern_1 = expr_1 and … and pattern_n = expr_n in expr .... evaluates expr_1 … expr_n in some unspecified order ....`Does any compiler or rutnime for OCaml take...

View Article

Nesting algebraic handlers from separate modules

Can algebraic handlers in OCaml be separated and put into different modules, then be nested together in some other file?For instance, say you have a program in a file called program.ml that uses a...

View Article

Can someone explain OCaml Tail Recursion Like I am five?

I cant wrap my brain around tail recursion specifically in ocaml also explain why one calls the "in" function at the end. P.S. I am talking most basic tail recursive function.

View Article
Browsing all 518 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>