ocaml

Which English tutorial would you advise to learn OCaml? [closed]

非 Y 不嫁゛ 提交于 2019-11-29 22:25:21
I want to advertise OCaml to beginners, and I am looking for good tutorials in English; not that you have only heard of, but that you have actually tried and found useful... I quite like the book Developing Applications With Objective Caml -- I guess the title should be updated to mirror the 'OCaml' naming decision. It is old and therefore slightly out-of-date, but on only minor aspects -- eg., it presents the stream syntax as belonging to the core language, but it is now outsourced as a Camlp4 extension. The book is surprisingly complete, and there is a lot of meat already in the chapters 2,

OCaml: Match expression inside another one?

独自空忆成欢 提交于 2019-11-29 22:05:45
I'm currently working on a small project with OCaml; a simple mathematical expression simplifier. I'm supposed to find certain patterns inside an expression, and simplify them so the number of parenthesis inside the expression decreases. So far I've been able to implement most rules except two, for which I've decided to create a recursive, pattern-matching "filter" function. The two rules I need to implement are: -Turn all expressions of the form a - (b + c) or similar into a - b - c -Turn all expressions of the form a / (b * c) or similar into a / b / c ...which I suspect would be fairly

Explaining pattern matching vs switch

僤鯓⒐⒋嵵緔 提交于 2019-11-29 20:25:24
I have been trying to explain the difference between switch statements and pattern matching(F#) to a couple of people but I haven't really been able to explain it well..most of the time they just look at me and say "so why don't you just use if..then..else". How would you explain it to them? EDIT! Thanks everyone for the great answers, I really wish I could mark multiple right answers. Having formerly been one of "those people", I don't know that there's a succinct way to sum up why pattern-matching is such tasty goodness. It's experiential. Back when I had just glanced at pattern-matching and

Should I learn Haskell or F# if I already know OCaml? [closed]

谁说我不能喝 提交于 2019-11-29 19:22:56
I am wondering if I should continue to learn OCaml or switch to F# or Haskell. Here are the criteria I am most interested in: Longevity Which language will last longer? I don't want to learn something that might be abandoned in a couple years by users and developers. Will Inria, Microsoft, University of Glasgow continue to support their respective compilers for the long run? Practicality Articles like this make me afraid to use Haskell. A hash table is the best structure for fast retrieval. Haskell proponents in there suggest using Data.Map which is a binary tree. I don't like being tied to a

Is there any free OCaml to C translator? [closed]

北城以北 提交于 2019-11-29 17:56:45
问题 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 6 years ago . So I have nice OCaml code (50000 lines). I want to port it to C. So Is there any free OCaml to C translator? 回答1: This probably isn't what you want, but you can get the OCaml compiler to dump its runtime code in C: ocamlc -output-obj -o foo.c foo.ml What you get is basically a static dump of the bytecode. The

Simple non-optimal unionfind in OCaml

江枫思渺然 提交于 2019-11-29 16:27:13
I wrote a OCaml program for union find algorithm. This algorithm I wrote is not optimal and is the simplest version. I put my OCaml code here because I am not sure whether this code is good enough or not (despite of the algorithm itself) , although this code can run without errors. This is the first time I wrote a complete working thing after I started to learn OCaml, so please help me by reviewing it. Useful suggestions will help me improving my OCaml skills. Thanks type union_find = {id_ary : int array; sz_ary : int array};; let create_union n = {id_ary = Array.init n (fun i -> i); sz_ary =

type level integers in ocaml

只愿长相守 提交于 2019-11-29 14:35:28
问题 Could anyone give me suggestions/advice on making type level integers in OCaml (3.12) supporting addition and subtraction operations on them? For example, if I have numbers represented like this: type zero type 'a succ type pos1 = zero succ type pos2 = zero succ succ ... I need a way to define function on types like this: val add: pos2 -> pos1 -> pos3 Little background: I'm trying to port some haskell code for operations on physical dimensions and i need the ability to define operations on

List Comprehension in Ocaml?

你离开我真会死。 提交于 2019-11-29 12:40:56
问题 It seems that Ocaml batteries have comprehension syntax: http://en.wikipedia.org/wiki/List_comprehension#OCaml However, what module should I include to use this syntax? I already open Batteries , but it doesn't work. Or is there a more idiomatic way to do list comprehension? I can use List.map and BatList.remove_if to achieve similar results, but that is much less elegant. 回答1: Currently there're two libraries in OCaml that provide list comprehension, one was formerly a part of OCaml

Why OCaml's threading is considered as `not enough`?

醉酒当歌 提交于 2019-11-29 11:59:41
问题 It seems many people are saying OCaml does not have a good capacity for concurrency and it is also not good for web server applications. I am currently learning ocaml's manual. It seems that OCaml provide concurrency now. Can I know why OCaml's concurrency/threading is considered as bad? Can I develop server application in OCaml? What problems may I meet? 回答1: See Concurrency vs. parallelism — What's the difference?. OCaml's threads offer concurrency, as you can have the next function start

How do I read in lines from a text file in OCaml?

被刻印的时光 ゝ 提交于 2019-11-29 11:28:00
问题 This is what I have so far. Isn't this all that you need? I keep getting the error "Error: Unbound module Std" let r file = let chan = open_in file in Std.input_list (chan) 回答1: If you don't have Extlib installed (and apparently you don't based on the error message above), then generally it's done something like this: let read_file filename = let lines = ref [] in let chan = open_in filename in try while true; do lines := input_line chan :: !lines done; !lines with End_of_file -> close_in