3 ms·
You might want to start with: http://blog.ezyang.com/2010/10/ocaml-for-haskellers/ http://blog.ezyang.com/2010/10/ocaml-for-haskellers/ and explore the language
by ignoramous 11y ago
You might want to start with: http://blog.ezyang.com/2010/10/ocaml-for-haskellers/ http://blog.ezyang.com/2010/10/ocaml-for-haskellers/ and explore the languages for what they are yourself.
I haven't tried Haskell apart from the very basic stuff, but if you have tried your hand at it for too long, and aren't able to make any headway, then you might as well invest time in learning OCaml/F# or Erlang or Idris or Rust or Elm instead. I hear Rust and Elm are pretty good too.
OCaml doesn't do mutli-core, I think [0], whilst Haskell has great support parallelism, concurrency [1]. Erlang, of course, is absolutely amazing at that too.
I primarily learn languages to expand my understanding of various programming constructs. It feels liberating to know that things are much easier in certain languages due to presence of certain constructs absent in other languages. For instance, OCaml is insanely good for compiler design and/or static analysis primarily due to 'variants' and the type system; Go (channels)/Erlang (actor-based programming, hot-plug code)/JVM-based languages (Clojure/Scala et al running on vastly optimized vm) for building massively concurrent systems; Ruby for being expressive, powerful, and simply awesome; JavaScript for... well... getting a taste of event-driven programming.
The challenges faced when using some of these languages are fascinating and at some point, it all comes together, as you try searching for a language in another language (like trying to mimic functional/reactive paradigms in Java 7 or below when faced with problems in handling "streaming data" for example).
In my personal experience, I have found strongly-typed languages to be easier to master and adopt in production than dynamically-typed languages.
----
[0] https://news.ycombinator.com/item?id=9582980 https://news.ycombinator.com/item?id=9582980
[1] https://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/ https://ghcmutterings.wordpress.com/2009/10/06/parallelism-c...
- cies 11y ago> OCaml/F# or Erlang or Idris or Rust or Elm I think PureScript deserves to be in this list as well :)
- rbehrends 11y ago> OCaml doesn't do mutli-core, I think Yes and no. Currently, OCaml has only cooperative or GIL-restricted multi-threading support, but multi-process/distributed systems work just fine (largely due to its built-in near universal serialization mechanism, which handles even closures). It's not perfect, but it's still functional.
- pathsjs 11y agoCan you expand on this point? When I tried OCaml a little time ago, it was a pain even to have a polymorphic print function. I would be surprised if there was a serialization mechanism that produces a binary form that cannot be adapted to produce a textual form
- rbehrends 11y agoHave a look at the Marshal module. Marshal can be polymorphic because it has compiler support and can rely on runtime internals (similar to how comparison is polymorphic or the Printf module can work). It works for pretty much everything where the representation is known to OCaml (the exceptions are things like extern C types wrapped in OCaml types). Example: let f x = 2 * x + 1 let s = Marshal.to_string f [ Marshal.Closures ] let g: (int -> int) = Marshal.from_string s 0 let () = Printf.printf "%d\n" (g 2) Note: this may not work in the REPL and you may have to put it in a file and compile it. Note also that serialization need not be polymorphic. See e.g. the s-expression mechanism [2], which relies on metaprogramming facilities. [1] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Marshal.html http://caml.inria.fr/pub/docs/manual-ocaml/libref/Marshal.ht... [2] https://realworldocaml.org/v1/en/html/data-serialization-with-s-expressions.html https://realworldocaml.org/v1/en/html/data-serialization-wit...
- pathsjs 11y agoThank you. s-exps are a pain, because you have to manually specify the function sexp_of_t for any type t that you want to support
- rbehrends 11y agoNo, that's what the ppx rewriter is for (the metaprogramming I mentioned). You write type foo = ... with sexp and those functions will be generated automatically for you. Mind you, the whole Jane Street Core machinery is still a bit heavyweight for my taste, but that particular concern shouldn't be an issue. For example, in utop: utop # #require "core";; utop # #require "core.syntax";; utop # open Core.Std;; utop # type foo = int * string with sexp;; type foo = int * string val foo_of_sexp : Sexp.t -> foo = <fun> val sexp_of_foo : foo -> Sexp.t = <fun> utop # sexp_of_foo (1, "foo");; - : Sexp.t = (1 foo)