ocaml

Why can't pervasives.cmi be opened?

醉酒当歌 提交于 2019-12-01 05:37:12
Installed Ocaml on my cygwin machine but simple compiles fail. Permissions are fine as you can see by the interaction below. OCAMLLIB is right; What is wrong? $ cat t.ml print_string "hi"; $ ocamlopt t.ml >> Fatal error: cannot open pervasives.cmi Fatal error: exception Misc.Fatal_error $ echo $OCAMLLIB /cygdrive/c/OCaml/lib $ ls -l /cygdrive/c/OCaml/lib/pervasives.cmi -rwxrwxrwx+ 1 Lyn None 15094 Oct 8 01:30 /cygdrive/c/OCaml/lib/pervasives.cmi A possible solution is to run this command in cygwin: export OCAMLLIB=C:\\OCaml\\lib The clue came from this message thread . 来源: https:/

How to read a bitmap in OCAML?

孤者浪人 提交于 2019-12-01 05:13:07
I want to read a bitmap file (from the file system) using OCAML and store the pixels (the colors) inside an array which have th dimension of the bitmap, each pixel will take one cell in the array. I found the function Graphics.dump_image image -> color array array but it doesn't read from a file. CAMLIMAGE should do it. There is also a debian package ( libcamlimage-ocmal-dev ), as well as an installation through godi , if you use that to manage your ocaml packages. As a useful example of reading and manipulating images in ocaml, I suggest looking over the code for a seam removal algorithm over

OCaml : why comparison operator are type agnostic, whereas arithmetic ones are not?

自闭症网瘾萝莉.ら 提交于 2019-12-01 03:49:49
I am wondering why < operator supports int, string, bool, or float, whereas + only support int. Could OCaml recognize the underlying arithmetic to use ? What makes comparison operator different from arithmetic ones ? Is it the same for other FP language ? Comparison operators are special in OCaml. They are able to compare records, variant types, lists and other data structures recursively. They by-pass a type system (hope I formulated it correct), and have a special support in runtime. I would recommend to read this post about OCaml polymorphic comparison. Comparison operators < , > , <> , =

Why can't pervasives.cmi be opened?

江枫思渺然 提交于 2019-12-01 03:46:37
问题 Installed Ocaml on my cygwin machine but simple compiles fail. Permissions are fine as you can see by the interaction below. OCAMLLIB is right; What is wrong? $ cat t.ml print_string "hi"; $ ocamlopt t.ml >> Fatal error: cannot open pervasives.cmi Fatal error: exception Misc.Fatal_error $ echo $OCAMLLIB /cygdrive/c/OCaml/lib $ ls -l /cygdrive/c/OCaml/lib/pervasives.cmi -rwxrwxrwx+ 1 Lyn None 15094 Oct 8 01:30 /cygdrive/c/OCaml/lib/pervasives.cmi 回答1: A possible solution is to run this command

Converting OCaml to F#: Differences between typing and type inference

断了今生、忘了曾经 提交于 2019-12-01 03:39:43
In researching type inference differences between F# and OCaml I found they tended to focus on nominative vs. structural type system . Then I found Distinctive traits of functional programming languages which list typing and type inference as different traits. Since the trait article says OCaml and F# both use Damas-Milner type inference which I thought was a standard algorithm, i.e. an algorithm that does not allow for variations, how do the two traits relate? Is it that Damas-Milner is the basis upon which both type inference systems are built but that they each modify Damas-Milner based on

ocamlyacc parse error: what token?

别来无恙 提交于 2019-12-01 03:05:20
I'm using ocamlyacc and ocamllex. I have an error production in my grammar that signals a custom exception. So far, I can get it to report the error position: | error { raise (Parse_failure (string_of_position (symbol_start_pos ()))) } But, I also want to know which token was read. There must be a way---anyone know? Thanks. Tokens are generated by lexer, hence you can use the current lexer token when error occurs : let parse_buf_exn lexbuf = try T.input T.rule lexbuf with exn -> begin let curr = lexbuf.Lexing.lex_curr_p in let line = curr.Lexing.pos_lnum in let cnum = curr.Lexing.pos_cnum -

How to read a bitmap in OCAML?

情到浓时终转凉″ 提交于 2019-12-01 02:31:26
问题 I want to read a bitmap file (from the file system) using OCAML and store the pixels (the colors) inside an array which have th dimension of the bitmap, each pixel will take one cell in the array. I found the function Graphics.dump_image image -> color array array but it doesn't read from a file. 回答1: CAMLIMAGE should do it. There is also a debian package ( libcamlimage-ocmal-dev ), as well as an installation through godi, if you use that to manage your ocaml packages. As a useful example of

Looking for OCaml IDE [closed]

余生长醉 提交于 2019-12-01 02:14:32
I like F# but sometimes I need something light and cross-platform and without .NET for sure. I tried to use OCamL many times but seems like I just can't start it. Installed IDEA, added OCamL plugin -> Doesn't work Installed eclipse ODT plugin -> Can't launch even config OCamL compiler - too complicated Even had tried NetBeans plugin a long time ago but even can't deal with it. So, for now, I'm using ocamlc -o "main.exe" "main.ml" from the command shell and different light editors. I don't use Vim or Emacs, I'm using nano and I have a habit of usage full-featured IDEs. I found various

How to implement a binary heap using list in OCaml?

混江龙づ霸主 提交于 2019-12-01 01:30:17
I am implementing a binary heap using list in OCaml, just to sharpen my OCaml skills. I feel it very difficult using list and after struggling for 2 days, I have to come here for suggestions and hints. Here is my thought so far Obviously, I can't use the orignal array based algorithm to implement it using list. What I am trying to utilise is binary tree . I have keep the invariant that a node should be bigger than any node whose level is lower than its. I roughly figured out how to implement insert , although I am not sure whether it is correct or not. For the binary tree, each node has two

verbose error with ocamlyacc

落花浮王杯 提交于 2019-12-01 00:23:57
In bison, it is sufficient to add %verbose-error to the file to make the parser errors more verbose. Is there any way to gain similar functionality with ocamlyacc? Here is the answer for a similar question, but I could not make anything out of it. This is how I call the lexer and parser functions: let rec foo () = try let line = input_line stdin in (try let _ = (Parser.latexstatement lexer_token_safe (Lexing.from_string line)) in print_string ("SUCCESS\n") with LexerException s -> print_string ("$L" ^ line ^ "\n") | Parsing.Parse_error -> print_string ("$P" ^ line ^ "\n") | _ -> print_string (