7,664 questions
3
votes
2
answers
91
views
Reusing polymorphic function in ocaml not working
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 ...
0
votes
1
answer
96
views
Conditional library dependencies in dune-project
This seems like it should be obvious bug how do I have a conditional dependency in dune-project? Specifically I want to depend on a library but only on Unix-like systems:
(package
(name foo)
(...
0
votes
0
answers
80
views
How to include an icon file in the source?
I am developing a server with Ocaml/Dream. The server can be installed with Opam and called from anywhere in the disk.
For the server icon, I use :
Dream.get (favicon_path)
(fun request ->
...
0
votes
1
answer
42
views
Failing to build incr_dom example ts_gui: date##getTime is the wrong type
I'm trying to build the incr_dom examples from here. I've succeeded with text_input, now I've moved on to ts_gui.
I copied the ts_gui directory into a directory outside of the incr_dom repo, added the ...
1
vote
0
answers
54
views
Adding C and C++ files to a dune build of ocaml app
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)
...
1
vote
1
answer
73
views
How can I implement OCaml's out_channel type?
Coming from Java, it's useful to be able to pass PrintStream instances around instead of directly writing to System.out or System.err deep in a call stack. That way output can either be captured in a ...
0
votes
0
answers
40
views
Detecting an unbounded objective in Z3 OCaml API
Is there a way in the OCaml Z3 API to detect, after optimizing a problem and getting a model, to check if the objective was actually unbounded?
One method I see is to add a constraint "I want ...
1
vote
0
answers
62
views
Could not update repository "diskuv-2.1.3": "git": command not found
I'm trying to install things to start doing stuff using OCaml, but somehow on Windows 11 it can't find "git" that is apparently installed
I've tried a lot of stuff: installing stuff from ...
1
vote
1
answer
43
views
Loading a file with multiple sexp in OCaml
I want to load a file with multiple sexp and get a list of sexp, and convert the list to a list of some custom type. I know that Core.Sexp.load_sexp_conv_exn filename ty_of_sexp can load a file with a ...
0
votes
0
answers
71
views
Ocaml using Core lib in windows
Having some trouble using [Core] library in windows.
For 5.x.x I'm getting the following error with open Core:
File "bin/dune", line 3, characters 7-11:
3 | (name main)
^^^^
** ...
4
votes
1
answer
130
views
How can I quickly split an utf8 string into chars in OCaml?
I'm handling a string with special characters and I want to split it into Unicode characters, but apparently OCaml strings are encoded in utf-8 while OCaml chars are 1-byte values, and it appears that ...
1
vote
1
answer
55
views
Ocaml parser for applying a function
I have a file, parser.mly, which has the following
%{
open Ast
%}
(* Ast holds the abstract syntax tree type definitions. *)
%token EOF
%token OR
%left OR
%start <Ast.prog> prog
%%
prog:
...
0
votes
2
answers
161
views
How to figure out the type of this function?
I try to figure out the type of the OCaml function below:
let subst = fun x -> fun y -> fun z -> x z (y z)
(* Or more concisely *)
let subst x y z = x z (y z)
Here's my derivation.
Step 1, ...
1
vote
1
answer
77
views
Is it possible to know if a text input is from a pipe only
I want to make a program that prompts the user to enter something with an introduction text. Something like "Please write something". But if there is a text from a pipe, the result is ...
1
vote
1
answer
100
views
Why two let expressions lead to compile error?
I have a let.ml containing below 2 lines:
let x = 1 in x + 1
let y = 1 in y + 1
When compile them with ocamlc, it says below error:
File "let.ml", line 2, characters 10-12:
2 | let y = 1 in ...
0
votes
2
answers
54
views
This expression has type unit but an expression was expected of type 'a Client.io
I am trying to write a simple executable code in OCaml below.
open Printf
open Lwt
open Cohttp
open Cohttp_lwt_unix
open Yojson
let () =
let ip = "8.8.8.8" in
let key = "" in
...
-1
votes
1
answer
64
views
Why a named function is still displayed as anonymous in utop?
(I am learning the OCaml and this may be a naive question.)
I use below code to define a named function a:
utop # let a = fun x -> x+1;;
val a : int -> int = <fun>
Note that the leading ...
1
vote
1
answer
70
views
Module type semantics in OCaml
I am new to OCaml and I am struggling a bit with understanding how module types work.
module type I = sig
type t
end
module EQ (M : I) = struct
let equal (x : M.t) (y : M.t) = x = y
end
(* ...
-1
votes
2
answers
68
views
Why my little monad in OCaml doesn't compile?
I'm learning Monad in OCaml, but it doesn't compile.
I reduced the code to reproduce the problem at easiest way :
file try.ml:
module type TRY = sig
type 'a t
val return : 'a -> 'a t
end
...
2
votes
1
answer
82
views
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 -...
0
votes
1
answer
208
views
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_all
let solve input = input
let () =
read_file "input.txt"
|> solve
|> print_endline
I am currently trying ...
0
votes
0
answers
60
views
How to debug this makefile error on a dune project
I cloned this repo
https://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 ...
3
votes
1
answer
185
views
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 ...
2
votes
1
answer
181
views
Using the OCaml reverse application operator |> to construct a function without wrapping it in a `fun ->` declaration
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 ...
1
vote
1
answer
99
views
Why does the OCaml function `read_line` have type `unit -> string`?
I understand that its return type is the string that is read but why does it need the parameter of type unit?