ocaml

When do you put double semicolons in F#?

匿名 (未验证) 提交于 2019-12-03 02:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is a stupid question. I've been reading a couple books on F# and can't find anything that explains when you put ;; after a statement, nor can I find a pattern in the reading. When do you end a statement with double semi-colons? 回答1: In the non-interactive F# code that's not supposed to be compatible with OCaml, you shouldn't need to ever need double semicolon. In the OCaml compatible mode, you would use it at the end of a top-level function declaration (In the recent versions, you can switch to this mode by using files with .ml

ocaml printf function: skip formatting entirely if some condition holds

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: (extracted from ocaml: exposing a printf function in an object's method , so it can be answered independently) I have the following (simplified) ocaml code, for a logger: type log_level = | Error | Warn | Info let ord lvl = match lvl with | Error -> 50 | Warn -> 40 | Info -> 30 let current_level = ref (ord Warn) let logf name lvl = let do_log str = if (ord lvl) >= !current_level then print_endline str in Printf.ksprintf do_log The logf function can be used with a printf format, as in: logf "func" Warn "testing with string: %s and int: %d"

Open and closed union types in Ocaml

风格不统一 提交于 2019-12-03 02:32:47
I'm looking into OCaml for the first time, having a bit of background with F# and Haskell. As such, a lot is familiar-looking, but one thing that isn't is the concept of "open" and "closed" unions (with the backtick and [< syntax). What are these useful for and how often are they used? Gilles 'SO- stop being evil' gasche's answer has good advice . I'm going to explain open and closed unions a bit more. First, you need to distinguish the two kinds of unions: basic variants (no backtick) and polymorphic variants (with backtick). Basic variants are generative: if you define two types with the

gcc ld: symbol(s) not found for architecture x86_64

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Alright so I'm making a lexer and a parser using Ocamlyacc. I've done my research and I think it's something to do with my makefile not picking the right bit version for my compiler or something like it? I don't know much about makefiles which is why I'm asking. I've run my program on another computer where it works without trouble so it gotta be something to do with my machine. It's a MacBook Pro 64 bit. I'm using Xcode 4.2.1. Here's the makefile: SHELL = /bin/sh C_C = gcc CPP_C = g++ ifdef GPROF C_CPP_FLAGS = -pg -O3 else ifndef DEBUG C

Good projects to learn OCaml and F# [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-03 02:10:40
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . After learning the basic syntax, reading some non-trivial code is a fast way to learn a language. We can also learn how to design a library/software during reading others' code. I have following lists. A Chess program in OCaml by Tomek Czajka. Hal Daumé has written several machine learning libraries in Ocaml.

What's really more performant? Haskell or OCaml [closed]

泄露秘密 提交于 2019-12-03 02:09:51
问题 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 6 years ago . I spent the last 18 months getting the grip of functional programming, starting with learning OCaml and for some weeks now Haskell.

Print a List in OCaml

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to do something as simple as this: Print a list. let a = [1;2;3;4;5] How can I print this list to Standard Output? 回答1: You can do this with a simple recursion : let rec print_list = function [] -> () | e::l -> print_int e ; print_string " " ; print_list l The head of the list is printed, then you do a recursive call on the tail of the list. 回答2: You should become familiar with the List.iter and List.map functions. They are essential for programming in OCaml. If you also get comfortable with the Printf module, you can then write: open

Would you please explain OCaml functors to me? [duplicate]

非 Y 不嫁゛ 提交于 2019-12-03 01:49:21
Possible Duplicate: In Functional Programming, what is a functor? I don't know much about OCaml, I've studied F# for some time and quite understand it. They say that F# misses functor model, which is present in OCaml. I've tried to figure out what exactly functor is, but wikipedia and tutorials didn't help me much. Could you please illuminate that mystery for me? Thanks in advance :) EDIT: I've caught the point, thx to everyone who helped me. You can close the question as exact duplicate of: In Functional Programming, what is a functor? If you come from an OOP universe, then it probably helps

OCaml and preprocessor have incompatible versions error when installing tcoq

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was trying to install tcoq and I had the following error: "/Users/pinocchio/.opam/4.05.0/bin/ocamlfind" ocamlc -rectypes -w -3-52-56 -c grammar/compat5.ml OCAMLC -c -pp grammar/gramCompat.mlp >> Fatal error: OCaml and preprocessor have incompatible versions Fatal error: exception Misc.Fatal_error make[1]: *** [grammar/gramCompat.cmo] Error 2 make: *** [submake] Error 2 does someone know: What the error means? How to fix it? I saw related post online: https://coq-club.inria.narkive.com/h4i0KOH0/problem-compiling-coq but it wasn't terribly

Writing an interpreter with OCaml GADTs

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing a small interpreter in OCaml and am using GADTs to type my expressions: type _ value = | Bool : bool -> bool value | Int : int -> int value | Symbol : string -> string value | Nil : unit value | Pair : 'a value * 'b value -> ('a * 'b) value and _ exp = | Literal : 'a value -> 'a exp | Var : name -> 'a exp | If : bool exp * 'a exp * 'a exp -> 'a exp and name = string exception NotFound of string type 'a env = (name * 'a) list let bind (n, v, e) = (n, v)::e let rec lookup = function | (n, []) -> raise (NotFound n) | (n, (n', v)::e