ocaml

Continuation Passing Style in ocaml

半腔热情 提交于 2021-02-18 18:00:33
问题 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 as let rec cont_sumlist lst c = match lst with | [] -> (c 0) | (h::t) -> cont_sumlist t (fun x -> c (h + x)) I am still confused on what the c means and what it does 回答1: A general answer is already given, but specifically, for cont_sumlist , in case of [] we "return" (i.e. feed) 0 into c that we're given ( 0 is

Continuation Passing Style in ocaml

偶尔善良 提交于 2021-02-18 17:59:33
问题 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 as let rec cont_sumlist lst c = match lst with | [] -> (c 0) | (h::t) -> cont_sumlist t (fun x -> c (h + x)) I am still confused on what the c means and what it does 回答1: A general answer is already given, but specifically, for cont_sumlist , in case of [] we "return" (i.e. feed) 0 into c that we're given ( 0 is

How to use type-level functions to create static types, dynamically?

做~自己de王妃 提交于 2021-02-18 17:39:14
问题 In TypeScript, there are type-level functions that allow creating new types based on given literal types/specifications (see Mapped Types, Conditional Types, etc.). For instance, here is such a function , let say provided by a lib author: type FromSpec<S> = { [K in keyof S]: S[K] extends "foo" ? ExampleType : never }; Its purpose is, given a specification S in the form of a map of string keys and arbitrary literals, it creates a new type in the form of a map with the same set of keys and with

Dune version not supported

微笑、不失礼 提交于 2021-02-11 14:21:21
问题 I am trying to install google-drive-ocamlfuse from source, but the prereuiqisites got me a little confused. I am experiencing this error: [bf@localhost google-drive-ocamlfuse]$ dune build @install File "/home/bf/.opam/default/lib/gapi-ocaml/dune-package", line 1, characters 11-15: 1 | (lang dune 1.11) ^^^^ Error: Version 1.11 of dune is not supported. Supported versions: - 0.0 - 1.0 to 1.7 I have dune version 1.7 installed: [bf@localhost google-drive-ocamlfuse]$ dune --version %%VERSION%% [bf

Dune version not supported

ぐ巨炮叔叔 提交于 2021-02-11 14:20:39
问题 I am trying to install google-drive-ocamlfuse from source, but the prereuiqisites got me a little confused. I am experiencing this error: [bf@localhost google-drive-ocamlfuse]$ dune build @install File "/home/bf/.opam/default/lib/gapi-ocaml/dune-package", line 1, characters 11-15: 1 | (lang dune 1.11) ^^^^ Error: Version 1.11 of dune is not supported. Supported versions: - 0.0 - 1.0 to 1.7 I have dune version 1.7 installed: [bf@localhost google-drive-ocamlfuse]$ dune --version %%VERSION%% [bf

List Recursion in Ocaml

ε祈祈猫儿з 提交于 2021-02-11 14:01:47
问题 This is what I want to achive, to return to a list with values that are below the given value with recursion : # list_below 3 [7; 1; 0; 3];; - : int list = [1; 0] # list_below 1 [-7; 1; 0; 3];; - : int list = [-7; 0] # list_below 9.0 [4.2; 3.6; 5.0; 12.8];; - : float list = [4.2; 3.6; 5.0] Here is what I wrote so far, and it does not appear to return anything. let rec list_below thresh lst = if List.hd lst > thresh then [] else List.hd lst :: list_below thresh (List.tl lst);; ;; Could you

OCaml : filter map and put the values into a list

天涯浪子 提交于 2021-02-11 04:53:35
问题 I can filter my map by key : module PairKeys = struct type t = string * string let compare (x0,y0) (x1,y1) = match String.compare x0 x1 with | 0 -> String.compare y0 y1 | c -> c end module StringMap = Map.Make(PairKeys);; .... let put_key_values_into_a_list (key_searched : string) = StringMap.filter (fun key -> key = key_searched) (* should return a list of the values in the filtered map *) After that, I want to put the values into a list. How can I do this in OCaml? Map.Make documentation :

Converting PCL to PDF

三世轮回 提交于 2021-02-07 13:30:44
问题 I am looking to create (as a proof-of-concept) an OCaml (preferably) program that converts PCL code to PDF format. I am not sure where to start. Is there a standardized algorithm for doing so? Is there any other advice available for accomplishing this task? Thanks! 回答1: Conversion of PCL to PDF can be incredibly complex (assuming you need it to be generic and not just for simple PCL). We've investaged this many times and in the end always revert to using other tools. We keep investigating as

OCaml - What data type is some and none?

谁都会走 提交于 2021-02-07 12:38:52
问题 If I am using Some and None combo in a list what would be the data type of the list? Is it always 'a ? Or is there some sort of a type for Some / None ? let listVar : (* type here *) list = [Some 4; Some 3; None; Some 2];; If I put int it gives me error: This expression has type int option * int option * 'a option * int option but is here used with type int When I put 'a it compiles fine but the basic OCaml tutorial says (I made references to other languages to explain my question better): It

How can I get the current system time in milliseconds or nanosec?

余生颓废 提交于 2021-02-05 06:17:25
问题 Unix.time() returns seconds. How can I get the time in ms or ns? Thanks 回答1: Try Unix.gettimeofday # Unix.time ();; - : float = 1447865942. # Unix.gettimeofday();; - : float = 1447865947.56802297 回答2: Core has very robust time related functions, and since 112.06.00 there is a Time_ns module. utop # Time_ns.now();; - : Time_ns.t = 2015-11-18 14:49:08.580109-05:00 来源: https://stackoverflow.com/questions/33785791/how-can-i-get-the-current-system-time-in-milliseconds-or-nanosec