7,665 questions
1
vote
0
answers
80
views
OCaml Log message printer
My lwt_reporter is as follows. It compiles and seems to work barring one instance. I am yet to log anything. Since I combine Lwt/Eio this may not work.
let lwt_reporter file =
let buf_fmt ~like =
...
1
vote
2
answers
71
views
Mtime.Span.pp vs Timedesc.pp
I try to use one these two Date/Time utilities as I don't find any such utility in Stdlib.
But here Timedesc prints 2026 Feb 06 16:20:24.641349077 +05:30:00 whereas Mtime prints 1hr10m( for example )....
3
votes
0
answers
74
views
Eta-Reduction in OCaml
let reverse_curry2 x = fun a b -> x b a;;
let twist f = fun x y -> reverse_curry2 f y x;;
Considering the above code, I'm not sure whether we can eta-reduce twist to the below, because that ...
3
votes
2
answers
128
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
108
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
137
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
1
answer
181
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
89
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
134
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
48
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
105
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
100
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
132
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
87
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
61
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 ...