Using the OCaml reverse application operator |> to construct a function...
I often find myself using the |> operator when constructing functions to pass as parameters to methods like List.find. For example, I have this code snippet:let parse_test_header (header : string...
View ArticleHow to access private definition from other library for testing
I have two libraries: lib/ dune src.ml src.mli test/ dune test.mlboth are libraries and I am testing in the test library with ppx_inline_test as i do not want them to be included in the librarydune...
View ArticleHow 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...
View ArticleHow can I get this expression to be of type string instead of string -> string?
I am learning OCaml and am having a bit of trouble with functional programming...I need to make a function that replaces a for a given list of integers, the cahracters at that index of a string. Say...
View ArticleOCaml how to build statically project
I've to prepare my OCaml project to compile/link/run on system where some libraries are not availible (yojson, curl, cryptokit but it's probably not so important) how may I do it?So far I was using:$...
View ArticleConvert OCaml tuple to function arguments
If I have a function returning a tuple (a * b * c) and I want to immediately pass it into another function with type a -> b -> c -> T, is there a way to do it other than tediously expanding it...
View Articlestring to list of char
I want to write a function that taking a string and return a list of char. Here is a function, but I think it is not do what I want ( I want to take a string and return a list of characters).let rec...
View Articleupdate installation ocaml/opam for msvc environment
I've installed ocaml under Windows11 using opam 2.2.1 default way, it works fine. I would try the msvc toolchain but unsure about the right way to do it. I'got VS 2022 community edition, reading ocaml...
View ArticleWhat does (string * string) list -> (string -> string) mean?
This might be a super dumb question, but I don't get it.What does(string * string) list -> (string -> string) mean?Especially the last part (string -> string). How can you achieve that?I...
View ArticleWhat does the `and` keyword mean in OCaml?
I'm mystified by the and keyword in OCaml. Looking through this code, I seetype env = { (* fields for a local environment described here *)}and genv { (* fields for a global environment here *)}then...
View Articleocaml order of parameters for fold
I executed the following command in utop with Jane street Base library installedopen Base;;List.fold;;It prints- : 'a list -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accum =...
View ArticleAdd two lists together in OCaml
let rec add_lists (xs : float list) (ys : float list): float list option = match xs, ys with | [], [] -> None | x :: xs, [] -> None | [], y :: ys -> None | x :: xs, y :: ys -> (x +. y) ::...
View ArticleFatal error: exception Invalid_argument("String.sub / Bytes.sub")
I am learning OCaml and working my way through the advent of code 2022.But it seems that reading the input.txt file is causing some issue.A XB YC ZI am getting this strange error, that comes from the...
View ArticleWhere is OCaml's alternative string syntax {|...|} documented?
OCaml's syntax for string literalslet s = "..."is explained in the manual at the expected position:https://caml.inria.fr/pub/docs/manual-ocaml/lex.html#s:stringliteralHowever, OCaml has an alternative...
View ArticleHow to debug this makefile error on a dune project
I cloned this repohttps://github.com/cucapra/gator and tried to run the makefile as per the first instruction in README. It seems to have already setup a dune project and just needs a build but I keep...
View ArticleCannot run Ocsigen app: "...ocsigenserver/var/run/ocsigenserver_command. I...
I'm on macOS Sonoma (M2), with ocaml 5.2.0 etc installed via opam (not using Homebrew). Then wanted to give Ocsigen a try.First install ocsigen:opam install ocsigenserverThen create the project:dune...
View ArticleUnbound module error in dune project even with library specified in build config
let read_file path = In_channel.with_open_bin path In_channel.input_alllet solve input = inputlet () = read_file "input.txt" |> solve |> print_endlineI am currently trying to run this code but...
View Articledeleting duplicates tail recursively in OCaml
I tried to write my own solution for this exercise by iterating through a list with a empty complst list where all non duplicates are inserted into and then get returned.I know it is a over complicated...
View Article"Error: Cannot find file '-lws2_32'" while compiling OCaml with OPAM on Windows
I'm following this tutorial to set up OCaml on windows. But the build process fails with this error:[ERROR] The compilation of ocaml-base-compiler.5.2.1 failed at "make -j7".#=== ERROR while compiling...
View ArticleOCaml try with issue
I don't anderstand the behaviour of the try ... with ... feature of OCaml.here is a little sample to reproduce my problem :let () = try int_of_string "4" with | Failure -> -1 | n -> nI compile...
View Article