ocaml

Pattern match on records with option type entries in OCaml

和自甴很熟 提交于 2019-12-11 09:38:34
问题 basically I have defined a record type like this: and exp = Bil_t.exp = { var: var option; binop: binop option; load: load option; store: store option; cast: cast option; inte: inte option; let_exp: let_exp option } And I am thinking to use a pattern match to process it, something like this: match rexp with | {None;binop;None;None;None;None;None} -> trans_binop @@ strip binop | {var;None;None;None;None;None;None} -> BU.inte_to_string @@ strip @@ mark inte | _ -> failwith "undefined" Sorry for

Ocaml unbound module

僤鯓⒐⒋嵵緔 提交于 2019-12-11 08:28:45
问题 I'm learning Ocaml language but i have a problem with my modules when i want to compile them. So, I have a module with the name Door and an other one with the name Case. Into each one, i have a type paramater with the other module : Door.mli type t = bool -> Case.u -> t Case.mli type u = bool -> Door.t -> u When i want to compile, i have this error : File "door.mli", line 14, characters 23-29: Error: Unbound module Case Have you got an idea ? Thanks you 回答1: You have two mutually recursive

Proven correct receipt module

匆匆过客 提交于 2019-12-11 08:21:40
问题 I'm working on a register which produces receipts when customers buy articles. As an exercise, I'm thinking about making a receipt module in Coq which cannot produce erroneous receipts. In short, the articles and the payments on the receipt should always sum to 0 (where articles have price > 0 and payments have amount < 0). Is this doable, or sensible? To do a quick sketch, a receipt would consist of receipt items and payments, like type receipt = { items : item list; payments : payment list

nested if -else loop error - ocaml

好久不见. 提交于 2019-12-11 07:16:37
问题 I am trying to work out a multiple if-else loop for my code. My previous code was: let rec appendtolist n list b = let f x = if ( b == 0 ) then x else (append (appendtocode n (List.hd list)) (appendtolist n (List.tl list) (b-1))) in f list ;; Modified code with nested loops: let rec appendtolist n list b = let f x = if b < 0 then x else if (b == 0) then appendtocode n (List.hd list) (b-1) else appendtocode n (List.hd list) :: appendtolist n (List.tl list) (b-1) in f list ;; But I get this

unbound module Event error when compiling Ocaml game

别说谁变了你拦得住时间么 提交于 2019-12-11 06:48:20
问题 Am new to Ocaml and i was trying to compile the game mltetris from http://lambda-diode.com/software/ocaml/. I am using windows 7 with ocaml version 4.00.0 however when i try to compile using the command below. I get this error C:\Users\WASSWA SAM\ocaml stuff\mltetris>ocamlc -pp camlp4o -o tetris.exe human. ml game.ml play.ml tetris.ml tetris.mli File "play.ml", line 21, characters 16-26: Error: Unbound module Event Isn't the Event Module supposed to be part of the standard distribution. I

Indentation of “if” in Ocaml under Emacs

ε祈祈猫儿з 提交于 2019-12-11 06:42:13
问题 I am coding Ocaml with Emacs, at the moment the setting of the indentation of if gives the following: if cond1 then e1 else if cond2 then e2 else if cond3 then e3 else e4 I would like to realize the same format as Caml programming guidelines: if cond1 then e1 else if cond2 then e2 else if cond3 then e3 else e4 Could anyone tell me which parameter is related to that? Thank you Edit1: here is my .emacs 回答1: Something seems to be wrong. Are you using the caml-mode from the OCaml distribution ?

Generating a list causes a stack overflow

不想你离开。 提交于 2019-12-11 06:39:15
问题 I'm generating a list of random numbers: let gen n = let rec pom l n = match n with | 0 -> l | _ -> let el = Random.int 20000000 in pom (el::l) (n-1) in pom [] n let lo = gen 1000000 What I get is Fatal error: exception Stack_overflow Why? I'm using tail recursion (and an accumulator) EDIT : You're right, the stack overflows on both sorts. But if my code had a zillion lines, it would be a pain to debug it this way. I'd like to use ocamldebug here, just as a learning experience. I ran

Optional dependencies with ocamlbuild

ⅰ亾dé卋堺 提交于 2019-12-11 06:38:37
问题 I have an OCaml project that is currently built using OCamlMake. I am not happy with the current build system since it leaves all build artefacts in the same directory as source files, plus it also requires to manually specify order of dependencies between modules. I would like to switch to a build system that does not suffer from these issues. I decided to give Oasis a try but have run into issues. The problems arise from the fact that the project is built in a very specific way. It supports

Core's `List.init` in Pervasives?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 06:09:48
问题 I'm used to JaneStreet's Core library. Its List module has a neat init function: List.init;; - : int -> f:(int -> 'a) -> 'a list = <fun> It allows you to create a list with using a custom function to initialize elements: List.init 5 ~f:(Fn.id);; - : int list = [0; 1; 2; 3; 4] List.init 5 ~f:(Int.to_string);; - : string list = ["0"; "1"; "2"; "3"; "4"] However, this function doesn't seem to exist in Pervasives , which is sad. Am I missing something, or do I have to implement it myself? And if

Transitive closure and equivalence classes

旧城冷巷雨未停 提交于 2019-12-11 05:40:33
问题 I want to ask about transitive closure and sorting in equivalence classes. I have an boolean matrix, the result I want is that, from the boolean matrix, I compute transitive closure, find equivalence class(es), and order all these equivalence class(es). For example: I have a graph 0 <-> 1 | v 2 I have 2 equivalence classes {{0; 1}; {2}}, and the result of sorting this class is: {2} after class {0; 1} 1) I want to understand more about why from transitive closure I can find equivalence classes