ocaml

Is there a way to export more things when I generate a parser with menhir?

廉价感情. 提交于 2020-01-06 03:39:07
问题 I'm using menhir to generate a parser and right now, the parser.mli file that it generated from my parser.mly file looks like this: (* The type of tokens. *) type token = (* ... huge ADT definition goes here ... *) (* This exception is raised by the monolithic API functions. *) exception Error (* The monolithic API. *) val start: (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Types.ast Is there a way to include more stuff in my parser's interface? In particular, I would like to be able to also

Seemingly equivalent Menhir rules change the shift/reduce conflicts found in grammar

你离开我真会死。 提交于 2020-01-06 03:05:40
问题 I'm using Menhir to create a parser, and there's a behaviour that always trips me, and I don't understand it. I have created the following minimal example to demonstrate it; this shows the declaration of the receiver argument in a method declaration in the Go language (http://golang.org/ref/spec#Method_declarations): %{ %} %token <string> T_identifier %token T_star %start <unit> demo %% (* This rule has a shift/reduce conflict demo: | option(T_identifier) option(T_star) T_identifier { () } *)

Z3 bindings on ocaml

梦想的初衷 提交于 2020-01-05 10:33:28
问题 I am currently using ocaml 4.06.0 and I am trying to use the Z3 sat solver. I am using opam's oasis to compile the files (which is building everything successfully). However, when I run the native code produced I am getting the following error: error while loading shared libraries: libz3.so . I tried reinstalling the z3 package but the error still persists. Can anyone help me solve this please because I have no idea what else to try? 回答1: Here is what I did just now to install z3 under Ubuntu

How to use List.map in OCaml

人走茶凉 提交于 2020-01-05 03:44:52
问题 I have a list of lists in OCaml returning [[7; 5]; [7; 3; 2]] . I know there's a lot of List functions in OCaml. I want to print each value out with a plus sign between them like one would do in Python or Ruby. In Python, I do this with print('+'.join(map(str,lst))) where lst is the list, str is to convert to a string. How do I do this in OCaml? Console Input int list list = [[7; 5]; [7; 3; 2]] Console Output 7 + 5 7 + 3 + 2 UPDATE let main num = print_string "Prime Partitions Program" in

OCaml: Why does renaming a type fail with “Their kinds differ”

依然范特西╮ 提交于 2020-01-05 01:12:21
问题 I'm building an universal container for for pairs of a type witness and a value of the witnessed type. This I want to use for several different types, which gives me errors because the types are all named the same. So I'm trying to rename types in the result of a functor like this: module type Witness = sig type 'a key type 'a value end module type Witnessed = sig type 'a key type 'a value type t type ('a, 'b) conv = { key : 'c . 'c key -> 'a; value : 'c . 'c value -> 'b; } val box : 'a key -

OCaml function calls happening in wrong order

淺唱寂寞╮ 提交于 2020-01-04 15:22:31
问题 Right, so this is an odd problem that really took me by surprise. Basically, I'm working on a build system that gives you the option of running shell commands before and after the main build. To execute these commands I'm just using Sys.command . The problem is that whenever I use that function it changes the order in which functions are called. For example: Sys.command "echo 'Hi!'"; Printf.printf "second\n"; Sys.command "echo 'Bye!'" outputs Hi! Bye! second from both the REPL and compiled

Cyclic type definition in OCaml

一曲冷凌霜 提交于 2020-01-04 09:37:53
问题 Obviously the following type definition is cyclic : type node = int * node;; Error: The type abbreviation node is cyclic My question is how comes the following one is not cyclic ? type tree = Node of int * tree;; The second definition also refers to itself. 回答1: One way to look at it is that node is an abbreviation for a type, not a new type itself. So the compiler (or anybody who's interested) has to look inside to see what it's an abbreviation for. Once you look inside you start noticing

LL(1) parser generator in OCaml

我怕爱的太早我们不能终老 提交于 2020-01-04 05:43:11
问题 I'm looking for a LL(1) parser generator in OCaml... Can anybody help me with this? 回答1: Well, LALR parsers can parse a strict superset of the languages which can be parsed by LL parsers. So I would advise simply using ocamlyacc which ships with Ocaml and is an LALR(1) parser generator. This may require some minor rewriting of the grammar, but it shouldn't be too hard. 回答2: Planck LL(n) parser combinator library: https://bitbucket.org/camlspotter/planck/overview It has started as my toy

OCaml 3.12.0 64 bit for Windows 7 64

空扰寡人 提交于 2020-01-04 02:58:11
问题 On http://caml.inria.fr/download.en.html I can only find the version 3.11.0 for Windows 32. Is there a precompiled OCaml 3.12.0 for Windows 64? 回答1: To provide a tidbit of information that could also have been provided there (but wasn't), there are roughly three categories of supported targets for the OCaml compilers. In the first category, common architectures, binaries are provided by INRIA: Windows 32-bit, Linux, Mac OS X. Targets platforms in the second category are those for which they

ocaml any types matching

别等时光非礼了梦想. 提交于 2020-01-04 02:20:08
问题 I'm trying to write a function that optionally take a function as argument let xxx ?(extractor = (fun a -> a)) yyy = ... This ends up having type: val xxx: ?extractor:('a -> 'a) -> 'c -> ... My intention is to have the extractor to be a function that extract information from a structure, so the return type can be anything, but I want the default to be identity function I tried to change the signature of it in the mli as val xxx: ?extractor:('a -> 'b) -> 'c -> ... But it does not compile,