ocaml Unbound value String.starts_with
I want to compile a simple program. Here is eyana.mllet () = Format.printf "%d\n" (List.length [7;8;9]); if String.starts_with ~prefix:"Eyana" "Eyana est très jolie!" then print_endline "C'est vrai"...
View ArticleContinuation Passing Style in ocaml
I am a bit confused on the concept. So I have the following function let rec sumlist lst = match lst with | [] -> 0 | (h::t) -> h + (sumlist t)With continuation, it can be written aslet rec...
View ArticleWhat is the safe and idiomatic way to check if two records (and two types in...
It seems like the codebase I'm working on complains if I'm using = or <> to check equality or inequality of two types that are not int types.I assume this was disabled so that I can't do the...
View ArticleCheck type of variable within a pattern match in OCaml
How do I check the type of a variable within a pattern matching in OCaml, version I currently use is 4.13, that is available online.I found this post: OCaml: Type Checking ObjectsBut it doesnt really...
View ArticleHow can OCaml dune test program find test input files?
── test├── dune├── test_program.ml└── foo_files├── foo_a└── foo_bHow can test_program find the files under folder foo_files when run using dune test?I can see that when the program is run, the current...
View ArticleWhy I get error "The type variable 'a occurs inside 'a t" with enabled...
I would like to write catamorphism in OCaml for any endofunctor (in terms of types) as a functor (in terms of OCaml):module type Functor = sig type 'a t (* ... *)endmodule Make(F : Functor) = struct...
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 ArticleImplementing functions in module types
I have the following module type:module type Element = sig type t type mystruct = {x: int; y: int} val (<) : t -> t -> bool val string_of_element : t -> string (* val (>) : t -> t...
View ArticleHow to forward the arguments of a constructor to a function in OCaml?
I have a type with constructors which take many arguments. When pattern matching on a constructor of this type, I would like to forward the arguments as a pack (maybe a tuple?), without having to...
View Articleocaml begin/end pattern matching
Haven't been able to find much online documentation regarding begin/end in ocaml. I have two different pattern matches in the same function (which I want to be independent of each other), but vscode is...
View Articlefind longest repeating sequence in list
If I have a List like this:[i;i;i;a;b;b;a;i;i;c] (*the longest repeating sequence would be [i;i]*)[i;i;i;i] (*here the max_pattern would be [i;i] (has to repeat, no overlapping*)[t;f;f;t] (*here it...
View ArticleKeepsorted function
I'm trying to solve a problem on a function called "keepsorted";This function has to keep a sub-list of growing number form a list called l1.For example if I have let l1 = [1; 2; 0; 1; 2; 4; 3; 5; 3;...
View ArticleOCaml error during after build when accepting command line input
I'm currently trying to learn OCaml via the "Real World OCaml: Functional Programming for the Masses" textbook. I've reached the point of trying to build my first executable after playing inside utop,...
View Articlemenhir `--interpret` for multiple files
I'm trying to use --interpret flag in Menhir to debug my parser, and I have separated my .mly files into tokens and grammar like this:.├── dune├── lexer.mll├── parser.mly├── syntax.ml└── tokens.mlyWhen...
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 ArticleDune's decoding and parsing of files
I am currently working on some project that involves Ocaml's build system Dune. However, in my work, there is some tasks that require taking a file (mainly its path) which contains some text written in...
View ArticleOCaml interpeter on the nintendo 3DS [closed]
In the last few days I was trying to create an interpreter for the nintendo 3DS, yet I was unable to. I do not think it is impossible, but it is certainly a not an easy project.My idea was to compile C...
View ArticleHow can I reliably load shared libraries from dune unit tests?
My project layout is roughly as follows:/├── src/│├── dune│├── libname.ml│└── libname.mli└── test/├── dune└── testname.mlThe test/dune file contains:(test (name testname) (modes byte exe) (libraries...
View ArticleMetaquot examples or documentation to generate code
I'm trying to write simple rewriters with ppxlib to get an idea of how to do more complex things.I'm currently struggling with metaquot. The documenation I found is this one but it just touches the...
View ArticleMetaquot: recognize a list pattern and store the resulting list
I have the following attribute attached to nodes [@profiling.mark [ "label1"; "label2"; "label3" ]] which gives me this AST:[{attr_name = {txt = "profiling.mark"}; attr_payload = PStr [{pstr_desc =...
View Article