ocaml

Sorting List with OCaml standard library function

*爱你&永不变心* 提交于 2019-12-24 03:52:13
问题 I'm studying OCaml and and doing various exercises on ordering data. I would like to understand how to use the standard librari List for ordering For example I would like to sort this array using these functions [94; 50; 6; 7; 8; 8] List.sort List.stable_sort List.fast_sort List.unique_sort What is the syntax to do it ? 回答1: If you want to use these functions on your list, you have to specifiy the comparison function. Quote from the documentation: The comparison function must return 0 if its

OCaml Stack of tuples

放肆的年华 提交于 2019-12-24 02:23:28
问题 I am trying to create a stack of tuples in OCaml using the following piece of code let (k : (string*string) Stack.t) = Stack.create ;; But when doing so i get an error while compiling telling Error: This expression has type unit -> 'a Stack.t but an expression was expected of type (string * string) Stack.t Am pretty new to OCaml. Can someone point out where I am going wrong? 回答1: Stack.create is a function which takes the value () (of type unit ) and give you back a stack. So you should do:

OCaml Stack of tuples

女生的网名这么多〃 提交于 2019-12-24 02:23:05
问题 I am trying to create a stack of tuples in OCaml using the following piece of code let (k : (string*string) Stack.t) = Stack.create ;; But when doing so i get an error while compiling telling Error: This expression has type unit -> 'a Stack.t but an expression was expected of type (string * string) Stack.t Am pretty new to OCaml. Can someone point out where I am going wrong? 回答1: Stack.create is a function which takes the value () (of type unit ) and give you back a stack. So you should do:

How to get OCaml linker flags to link with C++ cmake build

十年热恋 提交于 2019-12-24 02:18:25
问题 I'm trying to link some C++/cmake code with some OCaml code. If the C++ side were simple, I'd just add its object file to ocamlopt. If the OCaml side were simple, I'd add its object file to cmake. But they're both complex programs with lots of dependencies. Currently, I have it working, but it's a bit of a hack: I run ocamlopt -output-obj to get the main OCaml object: add_custom_command( OUTPUT ocaml_main.o DEPENDS ocaml.ml COMMAND ocamlfind ocamlopt -package mylib -linkpkg -output-obj -o

ocaml command line cannot find “topfind”

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:13:59
问题 I've installed opam , run opam init , run opam switch 4.06.0 which created a 4.06.0 directory inside ~/.opam , run "eval opam confing env " which exports $OCAML_TOPLEVEL_PATH as ~/.opam/4.06.0/lib/toplevel amongst other things, when launching ocaml I get the dreaded: $ ocaml OCaml version 4.06.0 Cannot find file topfind. Unknown directive `camlp4o'. # I've looked at this and this neither of which address my issue and I'm at my wits' end (first time setting up OCaml). This is my ~/.ocamlinit :

Why OCaml does not allow function matching? [closed]

a 夏天 提交于 2019-12-24 02:04:49
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . if I do match (fun i -> i + 1) with (fun i -> i + 1) -> true;; It got rejected. Why OCaml does not allow function matching? 回答1: There

Why OCaml does not allow function matching? [closed]

℡╲_俬逩灬. 提交于 2019-12-24 02:04:03
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . if I do match (fun i -> i + 1) with (fun i -> i + 1) -> true;; It got rejected. Why OCaml does not allow function matching? 回答1: There

Is this handling of ambiguities in dypgen normal or is it not?

风流意气都作罢 提交于 2019-12-24 01:26:29
问题 I would like to know, if this is a bug or behavior, that is intended by the inventor. Here I have a minimal example of a dypgen grammar: { open Parse_tree let dyp_merge = Dyp.keep_all } %start main %layout [' ' '\t'] %% main: | a "\n" { $1 } a: | ms b { Mt ($1,$2) } | b <Mt(_,_)> kon1 b { Koo ($1, $2, $3) } | b <Mt(_,_)> kon2 b { Koo ($1, $2, $3) } | b { $1 } b: | k { $1 } | ns b { Nt ($1,$2) } /* If you comment this line out, it will work with the permutation, but I need the 'n' ! */ /* | b

ocamlopt linking error code 2

末鹿安然 提交于 2019-12-24 01:18:40
问题 I ran the command opam install ocamlbuild and it seems that I have some kind of problem with ocamlopt Here is what opam is telling me : (I'm guessing it just doesn't like my 4.04 version) ### stdout ### # [...] # mkdir -p tmp # ocamlopt.opt -pack src/const.cmx src/loc.cmx src/discard_printf.cmx src/signatures.cmi src/my_std.cmx src/my_unix.cmx src/tags.cmx src/display.cmx src/log.cmx src/shell.cmx src/bool.cmx src/glob_ast.cmx src/glob_lexer.cmx src/glob.cmx src/lexers.cmx src/param_tags.cmx

match case unused in OCaml

99封情书 提交于 2019-12-24 00:09:33
问题 I want to build a list of type (char, 'a list) list where each char is an upper case letter of the alphabet. I'am getting a warning Warning 11: this match case is unused. for the second match case on get_list. I did some prints on the first case and found out len get's there with value 0, so it never uses the second case. What's happening? let rec get_list abc i len = match i with | len -> [] | _ -> ((String.get abc i), [])::get_list abc (i + 1) len in let rec print_list l = match l with | []