7,662 questions
3
votes
2
answers
116
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
85
views
CSRF token could not be verified whenever server restarts
I use OCaml/Dream to create a simple HTML form (No sensitive data at all).
let form_page request =
let _csrf_token = Dream.csrf_token request in
Dream.html (Printf.sprintf {|
<form action="/...
0
votes
1
answer
130
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)
(...
1
vote
1
answer
168
views
How do I create a new module type by reusing another type?
I started using this pattern to obviate the need to repeat the complex type everywhere. Now I don't have many repetitions and the idea works.
module type RadixNode = sig
type 'a t
end
module ...
0
votes
0
answers
85
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 ->
...
3
votes
2
answers
129
views
Type mismatch: Expecting type Empty.t but got type int
I wrote a module with a signature but got an error when executing a function from within this module.
module Empty: sig
type t
val double: t -> t
end = struct
type t = int
let double (x: ...
0
votes
1
answer
44
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 ...
3
votes
2
answers
96
views
What's the OCaml equivalent of C's printf("%.3s"), i.e, specifying a maximum width for a string argument?
In C, one can write:
printf("%.3s", "foobar");
To get foo printed as a result (that is, print the initial part of a string).
In OCaml, Printf.printf "%.3s" "foobar&...
3
votes
1
answer
87
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)
...
0
votes
1
answer
119
views
Mismatched Types in Oxcaml Tutorial
Im trying to follow the tutorial for oxcaml but the provided code copied directly from said tutorial has multiple errors
let result = Scheduler.schedule scheduler ~monitor ~f in
...
1
vote
1
answer
82
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 ...
3
votes
1
answer
60
views
How can I use the sexp_diff library as input to the pp_diff parameter of OUnit's assert_equals?
My use-case is that I am writing tests for a parser. The parser outputs an AST which I convert to an s-expression of sexplib type. I want to compare this s-expression to an expected parse tree, also ...
0
votes
0
answers
44
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 ...
2
votes
1
answer
113
views
How to parse comments and keep them?
I am creating a tool that transpiles a language that is pretty much OCaml to valid OCaml code.
Now, I absolutely need to keep comments (in the correct places) when transpiling to OCaml.
The problem is ...
1
vote
0
answers
69
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 ...