ocaml

opam upgrade wants to downgrade a bunch of packages

試著忘記壹切 提交于 2019-12-07 16:40:49
问题 I just tried an 'opam upgrade' and got (the final summary): 1 to install | 59 to reinstall | 3 to upgrade | 34 to downgrade | 0 to remove Do you want to continue ? [Y/n] Downgrading 34 packages makes me nervous. Why would it want to do this? Some examples of packages it wanted to downgrade: downgrade llvm.3.2 to 3.1 downgrade ocamlfind.1.4.0 to 1.3.3 [required by bitstring, camltc, ezjsonm, fat-filesystem, google-drive-ocamlfuse, merlin, mirage-block-xen, mirage-console-xen, mirari, utop]

How to make a covariant observable in OCaml

女生的网名这么多〃 提交于 2019-12-07 14:16:16
问题 I'm trying to make a wrapper for values that allows callers to register themselves for notifications about it. Here's some (working) code: module Thing : sig type +'a t val make : 'a -> 'a t val watch : ('a -> unit) -> 'a t -> unit val notify : 'a t -> unit end = struct type 'a t = { obj : 'a; watchers : (unit -> unit) Queue.t } let make x = { obj = x; watchers = Queue.create () } let watch fn x = x.watchers |> Queue.add (fun () -> fn x.obj) let notify x = x.watchers |> Queue.iter (fun fn ->

android ndk: are -fPIC and -pie mututally exclusive?

只谈情不闲聊 提交于 2019-12-07 14:11:52
问题 I'm building Unison (a file synchronization executable) for Android using the Android r10e NDK, but this isn't really an Android question. Android > 5.0 (SDK 21) requires executables to be position-independent. So I pass -pie to arm-linux-androideabi-gcc while compiling, which works: % hardening-check ./unison ./unison: Position Independent Executable: yes ... This works fine on Android 5.0 devices. Android > 6.0 (SDK 21) still requires executables to be position-independent, but also

Remove the comments generated by cpp

做~自己de王妃 提交于 2019-12-07 10:23:27
问题 I use #include ".../frontend/tokens.mll" in lexer.mll , and then cpp -C -P frontend/lexer.mll -o frontend/lexer_new.mll to generate lexer_new.mll . That worked until I upgraded my ubuntu from 12.04 to 14.04 yesterday. The compilation gives an error: ocamllex frontend/lexer_new.mll File "frontend/lexer_new.mll", line 1, character 1: illegal character /. make: *** [frontend/lexer_new.ml] Error 3 That is because in lexer_new.mll several lines of C comments have been inserted in the beginning: /*

reversing a list in OCaml using fold_left/right

时光怂恿深爱的人放手 提交于 2019-12-07 07:32:36
问题 UPDATE - Solution Thanks to jacobm for his help, I came up with a solution. // Folding Recursion let reverse_list_3 theList = List.fold_left (fun element recursive_call -> recursive_call::element) [] theList;; I'm learning about the different ways of recursion in OCaml (for class) and for some exercise, I'm writing a function to reverse a list using different recursion styles. // Forward Recursion let rec reverse_list_forward theList = match theList with [] -> [] | (head::tail) -> (reverse

What's the difference between records and tuples in OCaml

喜夏-厌秋 提交于 2019-12-07 06:22:48
问题 Is there any difference between records and tuples that is not just a syntactic difference ? Is there a performance difference ? Is the implementation the same for tuples and records ? Do you have examples of things that can be done using tuples but not with records (and conversely) ? 回答1: Floats fields in float-only records or arrays are stored unboxed, while no such optimization applies to tuples. If you are storing a lot of floats and only floats, it is important to use records -- and you

Where/how to declare the unique key of variables in a compiler written in Ocaml?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 05:49:21
问题 I am writing a compiler of mini-pascal in Ocaml. I would like my compiler to accept the following code for instance: program test; var a,b : boolean; n : integer; begin ... end. I have difficulties in dealing with the declaration of variables (the part following var ). At the moment, the type of variables is defined like this in sib_syntax.ml: type s_var = { s_var_name: string; s_var_type: s_type; s_var_uniqueId: s_uniqueId (* key *) } Where s_var_uniqueId (instead of s_var_name ) is the

Difference between module and package Ocaml

跟風遠走 提交于 2019-12-07 04:08:13
问题 I'm basically trying to follow this stackoverflow answer located in this post: What is the best module for HttpRequest in OCaml and I'm running in to problems. When I am trying to run a single file with just open Lwt ;; I am getting and error saying it is an unbound module. I have run the following opam instruction: opam install lwt and it did install the correct package . So I think the problem is the difference between a module and a package, which I don't really understand. I was looking

How to print a tree structure into a string fast in Ocaml?

戏子无情 提交于 2019-12-07 03:35:33
问题 Assume I have a mathematical expression in a "tree" form in OCaml. It's represented as an algebraic type like this: type expr = Number of int |Plus of expr*expr Well, this is a very simplified definition, but it's enough to describe the problem. I want to convert it to a string in a reverse polish notation, so that Plus (Number i, Number j) becomes (+ i j) . A straightforward implementation would be let rec convert = function Number i -> string_of_int i |Plus (a,b) -> (let s = convert a in

How to use assert in OCaml?

China☆狼群 提交于 2019-12-07 03:08:22
问题 I am trying to learn OCaml and I am having trouble with the assertion statement. In the interpreter I can use it: Zameers-MacBook-Air:~ zmanji$ ocaml OCaml version 4.01.0 # let x = 1;; val x : int = 1 # assert(x > 2);; Exception: Assert_failure ("//toplevel//", 1, 0). # ^D However when I put the code in a file that looks like this: let x = 1 assert(x > 2) I get the following error: Zameers-MacBook-Air:Q4 zmanji$ ocaml test.ml File "test.ml", line 2, characters 0-6: Error: Syntax error What am