How to split a list in two list
I have to make a function who splits a number list int two list:[Int(17);Float(18.9);Int(777);Float(15.5)] -> [Int(17);Int(777)] , [Float(18.9);Float(15.5)]type number = | Int of int | Float of...
View ArticleHow can I handle errors in OCaml when using ncurses?
I'm learning OCaml, and I want to write a curses application. I'm very new to this language, and as I started writing the curses functions, I noticed that many of them have the type unit -> err. I...
View ArticleI get an error when I add more functions to my test file which uses OUnit2
I wanted to know which library could be used for testing programs in OCaml and how can I automate those tests in github, I have somewhat done it but when I add more functions, the newer functions...
View ArticleDifference between two kinds of recursive function
In OCaml, there are two ways I have seen to write a map function for examplelet rec map f xs = match xs with | [] -> [] | x::rest -> f x :: map f restandlet map f xs = let rec go xs = match xs...
View ArticleOCaml - a function which returns all the prefixes of a list
For [1;2;3] , I want to return [[]; [1]; [1; 2]; [1; 2; 3]] . I have hit a wall and i need help, this is what i have done so farlet rev list = let rec aux acc = function | [] -> acc | h::t -> aux...
View ArticleHow can I simplify nested pattern matching clauses?
I have nested data types with a lot of option modifiers. I want to simplify the source code of functions when I need to match the nested types.Consider example:type ty = Ty1 | Ty2let func = function |...
View ArticleHow to apply a function in an iterable list
so I am new to OCaml and im having some trouble with lists.What I have is a List of chars as follows:let letters = [a;b;c;d]I would like to know how can I iterate the list and apply a fuction that...
View ArticleHow can I handle a parameter sequence in Ocamlyacc for a program written in...
I am currently working in an parser for Rustine using ocamllex and ocamlyacc and I would like my parser to recognize pattern such as fn add(x:i32, y:i32) ( for now ). I have written a lexer.mll and a...
View ArticleLexical vs dynamic scoping
Would the OCaml expression let x = 5 in (let x = 6 in x) evaluate differently for dynamic vs lexical (static) scoping?when would an expression evaluate differently for dynamic vs lexical scoping...
View ArticleDebugging with dune
I know of the OCaml debugging tool (first compile with ocamlc -g <file>, then run ocamldebug <output>) and also the function call tracing feature in the toplevel (both covered here)....
View Articlesolver_get_unsat_core() in ML (OCaml) API returns empty core
I am trying to write a simple Z3 problem using the OCaml API to extract an unsat core. The problem is that the unsat core returned is empty when it should not be. Do you have any ideas or can you point...
View ArticleWindows support for Jane Street OCaml Core?
I am reading https://realworldocaml.org/ (which is an amazing book by the way) and all of the examples assume use of the Jane Street Core library. I am not yet familiar with the OCaml environment and...
View ArticleInstalling core on 64 bit OS
I'm trying to install the Janestreet Core library on windows via cygwin and I get the following error messagecore unmet availability conditions, e.g. os != "win32"Can I not use the application at all...
View ArticleWaiting for Writer.write to complete in Caml Async
I have the following simple OCaml Async job which is supposed to write to a file and terminate the process. Unix.openfile "foobar" ~mode:[`Creat;`Rdwr]>>= fun fd ->let wr = Writer.create fd...
View ArticleCan't find .ocamlinit file
I'm trying to get an OCaml environment set up for the Real World OCaml book.I need OCaml, OPAM, Utop and the Core library. I've been able to install OCaml, OPAM and Utop but I have problems setting up...
View ArticleOCaml standard Map vs. Jane Street Core.std Map
So I'm using Jane Street's Core.std for certain things in my program but still want to use the standard OCaml Map. However, when I call functions like mem, it expects the signature of the Core.std...
View ArticleConcurrent write with OCaml Async
I'm reading data from the network and I'd like to write it to a file whenever I get them. The writes are concurrent and non sequential (think P2P file sharing). In C, I would get a file descriptor to...
View ArticleHow to define custom exception printers using Janestreet Core?
By default, a Failure exception is printed as such:# print_endline (Printexc.to_string (Failure "uh\noh"));;Failure("uh\noh")For improved readability, we want to print the argument of Failure as is...
View ArticleWhy is this happening (Ocaml)
In Ocaml language the goal was to combine(append) two lists while removing the duplicates.let rec find_dup a lst = match lst with | [] -> false | hd::tl -> if (hd == a) then true else find_dup a...
View Articledeleting 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