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

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 Article


How 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 Article


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...

View Article

How 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 Article

OCaml 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 Article


Convert 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 Article

string 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 Article

update 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 Article


What 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 Article


What 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 Article

ocaml 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 Article

Add 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 Article

Fatal 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 Article


Where 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 Article

How 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 Article


Cannot 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 Article

Image may be NSFW.
Clik here to view.

Unbound 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 Article


deleting 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 Article

OCaml 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
Browsing all 518 articles
Browse latest View live


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