ocaml

ocaml batteries compiling : Unbound module Toploop

大兔子大兔子 提交于 2019-12-02 06:25:43
问题 **Build mode: shared ocamlbuild -no-links syntax.otarget byte.otarget src/batteries_help.cmo META shared.otarget Finished, 0 targets (0 cached) in 00:00:00. + ocamlfind ocamlc -c -g -annot -warn-error A -package camomile,num,str -package camlp4.lib -pp camlp4of -pp camlp4of -I libs/estring -I benchsuite -I src -I testsuite -I build -I qtest -I libs -I src/syntax/pa_comprehension -I src/syntax/pa_strings -o libs/estring/pa_estring_top.cmo libs/estring/pa_estring_top.ml File "libs/estring/pa

Combining a column of lists in OCaml

淺唱寂寞╮ 提交于 2019-12-02 06:17:46
I want to essentially transpose a matrix in OCaml (without using recursion or any sort of looping) For example, if I have the following matrix: [[1;2];[3;4]] , I want to have the output of [[1;3];[2;4]] . What I have done so far is break the original matrix into individual columns: //function that separates into cols let separate li = List.map (fun x -> [x]) li;; I call this helper function from another function: let trans x = List.concat (List.map separate li) x;; I was thinking this would combine all the columns the way I want to but rather, ended with the following output: [[1];[2];[3];[4]]

How to convert a string to integer list in ocaml?

我与影子孤独终老i 提交于 2019-12-02 04:32:49
I need to pass two list as command line arguments in ocaml. I used the following code to access it in the program. let list1=Sys.argv.(1);; let list2=Sys.argv.(2);; I need to have the list1 and list2 as list of integers. I am getting the error This expression has type string but an expression was expected of type int list while processing. How can I convert that arguments to a list of integers. The arguments are passed in this format [1;2;3;4] [1;5;6;7] Sys.argv.(n) will always be a string. You need to parse the string into a list of integers. You could try something like this: $ ocaml OCaml

ocaml batteries compiling : Unbound module Toploop

≯℡__Kan透↙ 提交于 2019-12-02 01:45:46
**Build mode: shared ocamlbuild -no-links syntax.otarget byte.otarget src/batteries_help.cmo META shared.otarget Finished, 0 targets (0 cached) in 00:00:00. + ocamlfind ocamlc -c -g -annot -warn-error A -package camomile,num,str -package camlp4.lib -pp camlp4of -pp camlp4of -I libs/estring -I benchsuite -I src -I testsuite -I build -I qtest -I libs -I src/syntax/pa_comprehension -I src/syntax/pa_strings -o libs/estring/pa_estring_top.cmo libs/estring/pa_estring_top.ml File "libs/estring/pa_estring_top.ml", line 18, characters 15-44: Error: Unbound module Toploop Command exited with code 2.**

Installing ocaml API for Z3 using opam

。_饼干妹妹 提交于 2019-12-02 01:10:38
I want to use Z3 in my OCaml program. Using opam, I did $ opam install z3 $ eval $(opam env) then tried compiling with $ ocamlfind ocamlopt -o main -package z3 -linkpkg main.ml What I get is a huge dump of thousands of In function foo undefined reference to bar , starting with /home/andrepd/.opam/4.06.1+flambda/lib/z3/libz3-static.a(api_datatype.o): In function `mk_datatype_decl': api_datatype.cpp:(.text+0x4bf): undefined reference to `__cxa_allocate_exception' api_datatype.cpp:(.text+0x522): undefined reference to `__cxa_throw' api_datatype.cpp:(.text+0x57b): undefined reference to `__cxa

How to make an interactive program?

依然范特西╮ 提交于 2019-12-02 00:51:15
I'm learning Ocaml and I need to create a program that can interact with the user in the following way: Program: "Welcome!" User: command1 arg1 arg2 program: "The answer is..." User: command2 arg program: "The answer is..." User: exit I need a scheme of the loop that make something like that Here's a loop that will read lines of input until it reaches end of file, or sees a line that says "exit". let rec loop () = match read_line () with | "exit" -> () | s -> Printf.printf "I saw %s\n%!" s; loop () | exception End_of_file -> () To call this loop in a source file, something like this will work:

Socket onread, onready, onclose event handler function in Ocaml

随声附和 提交于 2019-12-02 00:41:21
I am developing a protocol using TCP/IP socket in Ocaml and I am interested implementing the event driven approach. Basically, I want to make event handling functions that invokes whenever socket receives a new data or closed or opened. Is it possible to do in Ocaml without implementing it manually using multiple threads? Thanks, Yes. Make a loop and use Unix.select to wait for events on your fds. You will have to set your sockets to non-blocking mode with Unix.set_nonblock so that your reads and writes don't block and you can get back to your select if there's no data to read/write (because

How to generate recursive list in OCaml

拥有回忆 提交于 2019-12-01 23:00:44
问题 I would like to implement analog of Haskell cycle function. If I pass list elements explicitly it seems trivial: let cycle a b c = let rec l = a::b::c::l in l cycle 1 2 3 generates recursive list 1, 2, 3, 1... But, how to generate recursive list on basis of another regular list? let cycle lst = ... Usage cycle [1;2;3] 回答1: In an eager language like ML, you need to use streams. For example # let cycle = Stream.from (fun n -> Some (List.nth [1;2;3] (n mod 3)));; val cycle : int Stream.t =

OCaml: get value's type name

浪子不回头ぞ 提交于 2019-12-01 21:46:07
Is is possible to print value's name in OCaml, for example if I have type my_type = | MyType_First of int | MyType_Second of string and then do something like: let my_value = MyType_First 0 in print_string ("my_value is of type " ^ String.from_type my_value ^ ".\n"; can I get "my_value is of type MyType_First." ? Thank you. Monomorphic solution: let from_type = function | MyType_First _ -> "MyType_First" | MyType_Second _ -> "MyType_Second" Polymorphic solution: none. (AFAIK, lexical tokens corresponding to constructors are not recorded in the bytecode/binary, even when debugging flags are

How to generate recursive list in OCaml

岁酱吖の 提交于 2019-12-01 21:43:25
I would like to implement analog of Haskell cycle function. If I pass list elements explicitly it seems trivial: let cycle a b c = let rec l = a::b::c::l in l cycle 1 2 3 generates recursive list 1, 2, 3, 1... But, how to generate recursive list on basis of another regular list? let cycle lst = ... Usage cycle [1;2;3] In an eager language like ML, you need to use streams. For example # let cycle = Stream.from (fun n -> Some (List.nth [1;2;3] (n mod 3)));; val cycle : int Stream.t = <abstr> # Stream.npeek 10 cycle;; - : int list = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1] As far as I can see, OCaml doesn