ocaml

error while installing ocamlfind.1.3.3 configure: m4 not in PATH; this is required

一曲冷凌霜 提交于 2019-12-12 12:34:58
问题 configure: m4 not in PATH; this is required I wonder how I can fix this. Thanks a lot! (I tried to copy the m4 folder to that path but it is not working) ==== ERROR [while installing ocamlfind.1.3.3] ==== # opam-version 1.0.0 # os linux # command ./configure -bindir /home/airobert/.opam/4.01.0dev+trunk/bin -sitelib /home/airobert/.opam/4.01.0dev+trunk/lib -mandir /home/airobert/.opam/4.01.0dev+trunk/man -config /home/airobert/.opam/4.01.0dev+trunk/lib/findlib.conf # path /home/airobert/.opam

Ocaml Variant Types

旧巷老猫 提交于 2019-12-12 12:23:41
问题 OCaml types have always really confused me no matter what tutorials/manuals I read. I need to define a type, let's say test, that does contains the following forms: a type ('a, 'b) test that has one of the forms: Empty, T t, N n, Seq [x1...xn] I know how to do the first 3, but I have absolutely no idea how to define the last form. This is what I have: type ('nonterm, 'term) test = | Empty | T of 'term | N of 'nonterm | ???? For seq, I need to match the instances of subexpressions x1 to xn. If

Converting OCaml to F#: Converting OCaml open_box and close_box to F#

对着背影说爱祢 提交于 2019-12-12 12:14:42
问题 I am converting several modules based on OCaml to F# and ran into the OCaml print formatting functions open_box and close_box from the OCaml format module. After reading about the concept of a printing box, it makes sense but seems like it needs a lot of work behind the scenes to implement. Is there an F# module that is functionally equivalent? If not, without having to convert portions of the OCaml format module, what are quick and simple replacement functions? EDIT Jack has a version as

Ocaml representation of values - Atoms

霸气de小男生 提交于 2019-12-12 12:11:06
问题 I looked at the internal representation of some OCaml values. The representation of an empty array is an atom(0) , i.e. a block with tag=0 and size=0 . Empty arrays of floats are represented by an atom(0) too. Is there any OCaml value represented by an atom with tag > 0 ? If not: for what purpose the OCaml bytecode set contains the ATOM n instruction? 回答1: A tag > 0 is used for constructors with arguments, which would make them not atoms. Constructors without arguments on the other hand are

How to configure _oasis for OCaml to set 'Profile' flag

笑着哭i 提交于 2019-12-12 11:26:38
问题 I have an existing project in OCaml and one _oasis file. I don't know where to enable the profiling flag for ocamlbuild . I looked up Oasis manual and the code, and found there was a variable profile available in setup.data. I assume this was what Oasis auto generated. Where and what should I include in _oasis to set profile to true ? 回答1: You can activate the ocamlbuild_more_args feature. On top of your _oasis file: AlphaFeatures: ocamlbuild_more_args Then, in your Package:

Why prefer currying to tuple arguments in OCaml?

痴心易碎 提交于 2019-12-12 10:37:10
问题 "Introduction to Caml" says Note, in Caml it is better to use Curried function definitions for multiple-argument functions, not tuples. when comparing 'a -> 'b -> 'c calling conventions to 'a * 'b -> 'c . When working with SML/NJ I got used to using tuple types for both input and output : ('a * 'b) -> ('c * 'd) so using tuples to express multiple inputs seems symmetric with the way I express multiple outputs. Why is currying recommended for OCaml function declarations over tuple arguments? Is

Convert 'a list to a Set?

倖福魔咒の 提交于 2019-12-12 10:36:34
问题 Is it really true that OCaml doesn't have a function which converts from a list to a set? If that is the case, is it possible to make a generic function list_to_set ? I've tried to make a polymorphic set without luck. Best regards, Lasse Espeholt 回答1: Fundamental problem: Lists can contain elements of any types. Sets (assuming you mean the Set module of the standard library), in contrary, rely on a element comparison operation to remain balanced trees. You cannot hope to convert a t list to a

Tree to ordered list with tail recursion

送分小仙女□ 提交于 2019-12-12 09:57:11
问题 I am actually sitting over a hour on a problem and don´t find a solution for it. I have this data type: type 'a tree = Empty | Node of 'a * 'a tree * 'a tree And i have to find a function which converts a given tree in a ordered list. There is also no invariant like that the left child has to be less then the right. I already found a "normal" recursion solution but not a tail recursive solution. I already thought about to build a unordered list and sort it with List.sort , but this uses a

How to use OCaml's [@tailcall] annotation to assert tail-recursiveness?

落爺英雄遲暮 提交于 2019-12-12 09:54:12
问题 In OCaml, the [@tailcall] annotation lets you assert that a particular function-call is a tail call (and so hopefully your whole function is tail recursive). The question is: Where do I place the annotation exactly? Obvious, easy example: let rec f = function | 0 -> 0 | x -> (f [@tailcall]) (x - 1) (* works like a charm *) But I don't see how I can do it in "less obvious" places: let rec f = function | 0 -> 0 | x -> (|>) (x - 1) f (* uh? *) I can see from the assembly code that the latter

How to schedule a task in OCaml?

北城余情 提交于 2019-12-12 09:27:44
问题 I have a task need to be done every 4 hours or once a day. In Java, it has quartz or spring or timer . But in OCaml, how do I do that? Any good lib for that? 回答1: I don't know any library to do that, but I think you can easily implement that kind of behavior using the Lwt library. Little example, to print Hello world every 4 hours : let rec hello () = Lwt.bind (Lwt_unix.sleep 14400.) (fun () -> print_endline "Hello, world !"; hello ()) Lwt.async (hello) The Lwt.async function call the