ocaml

Haskell, Scala, Clojure, what to choose for high performance pattern matching and concurrency [closed]

会有一股神秘感。 提交于 2019-12-02 14:28:59
I have started work on FP recently after reading a lot of blogs and posts about advantages of FP for concurrent execution and performance. My need for FP has been largely influenced by the application that I am developing, My application is a state based data injector into another subsystem where timing is very crucial (close to a 2 million transactions per sec). I have a couple of such subsystems which needs to be tested. I am seriously considering using FP for its parallelism and want to take the correct approach, many posts on SO talk about disadvantages and advantages of Scala, Haskell and

Ideas for Natural Language Processing project? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-02 14:19:26
I have to do a final project for my computational linguistics class. We've been using OCaml the entire time, but I also have familiarity with Java. We've studied morphology, FSMs, collecting parse trees, CYK parsing, tries, pushdown automata, regular expressions, formal language theory, some semantics, etc. Here are some ideas I've come up with. Do you have anything you think would be cool? A script that scans Facebook threads for obnoxious* comments and silently hides them with JS (this would be run with the user's consent, obviously) An analysis of a piece of writing using semantics, syntax,

When should objects be used in OCaml?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 14:06:31
Usually, an OCaml program can be written with or without objects. When is it most beneficial to use objects, and when should they be avoided? As a general rule of thumb, don't use objects. The additional complexity they bring in is not that often worth it. I think that's a rule that apply to other languages as well, but that's another story. At least with OCaml one can objectively (no pun intended) say that the common practice is to not use object except in rare cases. Object provide a bundle of: A "standard" style for carrying around and using records of functions, with possibly polymorphic

Why is writing a compiler in a functional language easier? [closed]

无人久伴 提交于 2019-12-02 14:02:37
I've been thinking of this question very long, but really couldn't find the answer on Google as well a similar question on Stackoverflow. If there is a duplicate, I'm sorry for that. A lot of people seem to say that writing compilers and other language tools in functional languages such as OCaml and Haskell is much more efficient and easier then writing them in imperative languages. Is this true? And if so -- why is it so efficient and easy to write them in functional languages instead of in an imperative language, like C? Also -- isn't a language tool in a functional language slower then in

Machine learning in OCaml or Haskell?

与世无争的帅哥 提交于 2019-12-02 13:49:20
I'm hoping to use either Haskell or OCaml on a new project because R is too slow. I need to be able to use support vectory machines, ideally separating out each execution to run in parallel. I want to use a functional language and I have the feeling that these two are the best so far as performance and elegance are concerned (I like Clojure, but it wasn't as fast in a short test). I am leaning towards OCaml because there appears to be more support for integration with other languages so it could be a better fit in the long run (e.g. OCaml-R ). Does anyone know of a good tutorial for this kind

Combining a column of lists in OCaml

倾然丶 夕夏残阳落幕 提交于 2019-12-02 09:28:16
问题 I want to essentially transpose a matrix in OCaml (without using recursion or any sort of looping) For example, if I have the following matrix: [[1;2];[3;4]] , I want to have the output of [[1;3];[2;4]] . What I have done so far is break the original matrix into individual columns: //function that separates into cols let separate li = List.map (fun x -> [x]) li;; I call this helper function from another function: let trans x = List.concat (List.map separate li) x;; I was thinking this would

Try to further understanding the interface/module of OCaml

心已入冬 提交于 2019-12-02 08:42:56
I understand in OCaml there are concepts of interfaces and module . And I understand how to use them now. However, what I don't understand is how to fully utilise them. For example, in Java, let's say we have a interface Map and we also have Hashtable and HashMap that implement Map . In code, I can do like: Map m = new Hashtable(); m.put("key", value); Someday, if I change my mind, I can change to Hashmap very quickly by changing Map m = new Hashtable(); to Map m = new HashMap(); , right? But how can I easily do that in Ocaml? For example, I have MapSig and 'HashMap:MapSig and "Hashtable

Adding line information to my AST in OCaml

不问归期 提交于 2019-12-02 08:14:55
问题 I am creating a compiler in OCaml where the grammar is as follow: type expr = | Cons of const | Var of string | List of ( expr list ) | Sum of ( expr * expr ) | Less_than of ( expr * expr ) | Conditional of ( expr * expr * expr ) | Array_literal of ( expr ) | Array_read of ( expr * expr ) The node of an AST looks like this: type 'a astNode = { data: 'a; metadata: Metadata; } and the Metadata module looks like this: module Metadata = struct type loc = Lexing.position type loc_range = loc * loc

Any simpler way to implement non-in-place selection sort in OCaml?

不羁岁月 提交于 2019-12-02 07:49:58
I implemented a non-in-place version of selection sort in OCaml. let sort compare_fun l = let rec find_min l' min_l origin_l = match l' with | [] -> if min_l = [] then (min_l, l') else let min = List.hd min_l in (min_l, List.filter (fun x -> if x != min then true else false) origin_l) | x::tl -> if min_l = [] then find_min tl [x] origin_l else let c = compare_fun (List.hd min_l) x in if c = 1 then find_min tl [x] origin_l else if c = 0 then find_min tl (min_l @ [x]) origin_l else find_min tl min_l origin_l in let rec insert_min l' new_l = match l' with | [] -> new_l | _ -> let (min_l, rest) =

create a histogram OCaml

风格不统一 提交于 2019-12-02 07:36:12
My task is to create a histogram that output the number of times that an element it is in a list. Input:[2;2;2;3;4;4;1] Output[(2, 3); (2, 2); (2, 1); (3, 1); (4, 2); (4, 1); (1, 1)] Expected output : [(2, 3); (3, 1); (4, 2); (1, 1)] My code: let rec count a ls = match ls with |[] -> 0 |x::xs when x=a -> 1 + count a xs |_::xs -> count a xs let rec count a = function |[] -> 0 |x::xs when x=a -> 1 + count a xs |_::xs -> count a xs let rec histo l = match l with |[] -> [] |x :: xs -> [(x, count x l)] @ histo xs ;; What have i done wrong? The issue is that xs contains potentially elements that are