ocaml

What does |> do?

坚强是说给别人听的谎言 提交于 2019-12-12 01:33:24
问题 From Real World OCaml , page 38(see https://realworldocaml.org/v1/en/html/variables-and-functions.html#prefix-and-infix-operators). It defines a function: # let (|>) x f = f x ;; and applied it to strings: # let path = "/usr/bin:/usr/local/bin:/bin:/sbin";; val path : string = "/usr/bin:/usr/local/bin:/bin:/sbin" # String.split ~on:':' path |> List.dedup ~compare:String.compare |> List.iter ~f:print_endline ;; /bin /sbin /usr/bin /usr/local/bin - : unit = () I am wondering - what does the

how to draw an automaton diagram?

痞子三分冷 提交于 2019-12-12 01:23:23
问题 I used graphviz based on the recommendation given to me by many people but I ran into a problem. I want to write a dot in ocaml using the Format.module and I have a record with five fields that define an automaton including the transitions which are represented by a list of int*char*int and final states which are represented by an int list. The first field is the initial state which is one int . I also defined a function member that takes a parameter and tests if it is a member of a given

Z3 Installation issue on windows 10

寵の児 提交于 2019-12-12 01:16:42
问题 I am trying to install Z3 package(https://github.com/Z3Prover/z3.git) I ran the following commands ./configure cd build make make install Installation was successfull. However when i run Ocamlfind list z3 component is not listed. So when i try to build my project which uses z3 , its failing with error ocamlfind: Package `Z3' not found. I did the following workarounds, a) added the z3.exe location to path b) I ran the following python command, but i got an error message saying its not able to

ocamllex regex syntax error

荒凉一梦 提交于 2019-12-12 00:54:32
问题 I have some basic ocamllex code, which was written by my professor, and seems to be fine: { type token = EOF | Word of string } rule token = parse | eof { EOF } | [’a’-’z’ ’A’-’Z’]+ as word { Word(word) } | _ { token lexbuf } { (*module StringMap = BatMap.Make(String) in *) let lexbuf = Lexing.from_channel stdin in let wordlist = let rec next l = match token lexbuf with EOF -> l | Word(s) -> next (s :: l) in next [] in List.iter print_endline wordlist } However, running ocamllex wordcount.mll

Recursion using OCaml and unzip

耗尽温柔 提交于 2019-12-12 00:53:42
问题 I did pattern matching, and it's working just fine: let rec unzip l = match l with |[] -> ([], []) |(x,y)::tail -> let (first, second) = unzip tail in (x::first, y::second) but how would I do this using map or fold right (tips only please don't tell me how to actually do it) I was thinking something along the lines of: let unzip : ('a * 'b) list -> 'a list * 'b list = let (first,second) = map (fun (x,y) -> (x::first, y::second) );; but getting syntax error 回答1: If you look at the type of List

OCaml: Object definition & cloning

好久不见. 提交于 2019-12-11 23:29:46
问题 class backup = object (self : 'mytype) val mutable copy = None method save = copy <- Some {< copy = None >} method restore = match copy with Some x -> x | None -> self end;; In this piece of code, there are several things I do not quite understand. (self: 'mytype) self means recursive class, but what is the role of 'mytype? Some {} gets a backup copy where copy is still None, and assign it to copy? Thank you!! 回答1: In C++, Java, and JavaScript the current object, the one executing the method,

Is it possible to let several lexers share same ident definitions?

谁说胖子不能爱 提交于 2019-12-11 23:25:42
问题 I have several lexers: lexer_1.mll , lexer_2.mll , ... Some definitions of ident ( let ident = regexp ) are common and repeated in these files. For instance, the definition of INTEGER , FLOAT , ... Does anyone know if it is possible to define them the once for all somewhere, and let the .mll files call it? 回答1: I'm afraid there's no "pure OCaml" solution, as ident seems to be systematically inlined by ocamllex . You can still put your regexp definition in a file, and use cpp (or any other C

Frama-C: Getting the values of statement

孤人 提交于 2019-12-11 23:23:59
问题 I want to develop a Frama-C-Plugin, where I get the values of the current statement. With the help of this post Frama-C Plugin development: Getting result of value-analysis I was able to print the values of the statements, but Pointers were not shown the way I need it. With the help of the comments, I was able to print the whole state (not only the variables of the statement). Can I combine these two: Get the variables of the statement, but also with pointers dereferenced (the value)? For

Ocaml Tree simple functions

点点圈 提交于 2019-12-11 20:44:57
问题 I created a tree type 'a tree = { mutable cont: 'a; mutable left: 'a bin_tree; mutable right: 'a bin_tree } and 'a bin_tree = Empty | Node of 'a tree;; and I'm struggling to do with some simple functions like insertion of elements (to the propper subtrees, no duplicates) making union of two binary trees I googled my problem but I'm constantly getting errors. For example: let rec insert x tree = match tree with Empty -> Node(x, Empty, Empty) | Node(y, left, right) -> if x <= y then Node(y,

Writing a function that is sum of functions

浪尽此生 提交于 2019-12-11 20:11:01
问题 I have the following excercise to do: Code a function that will be a summation of a list of functions. So I think that means that if a function get list of functions [f(x);g(x);h(x);...] it must return a function that is f(x)+g(x)+h(x)+... I'm trying to do code that up for the general case and here's something I came up with: let f_sum (h::t) = fold_left (fun a h -> (fun x -> (h x) + (a x))) h t;; The problem is I'm using "+" operator and that means it works only when in list we have