5 ms·
> Because there's functional as in only using pure functions (Haskell, ocaml) This is not true. Having written a good amount of OCaml I would argue that progra
by krat0sprakhar 11y ago
> Because there's functional as in only using pure functions (Haskell, ocaml)
This is not true. Having written a good amount of OCaml I would argue that programming with side-effects in OCaml is extremely approachable - almost as much as Clojure. There are mutable data structures in the stdlib (Array, Hashtbl) and IO etc. is straightforward. Like Clojure, there exists a ref type which can be easily mutated. It's one of the reasons why OCaml strikes as an extremely pragmatic language to me.
- Scarbutt 11y agoleaving runtime asides, which do you enjoy more Ocaml or Clojure?
- ohnomrbill 11y agoI use both, for different things. Clojure is more easily concurrent, and I love ClojureScript, so I tend to use it for web applications. OCaml is extremely useful for native code (I write a lot of personal productivity tools in OCaml).
- krat0sprakhar 11y agoTo add to ohnomrbil's succinct reply, I absolutely enjoy being scolded by OCaml's compiler. The type inference is just marvelous and the code is almost as concise as Python etc. OTOH, the library ecosystem for OCaml is not even close to the stuff that's available for Clojure.
- catnaroek 11y agoI'd distinguish between (at least) three degrees of “purity”: (0) Absolutely anything goes. Examples: Racket (in the REPL), Lisp, Clojure, Scala, Erlang, etc. (1) Values are immutable, but any computation might have any effect. Examples: Standard ML, OCaml (mostly), Racket (mostly). (2) Values are immutable, and computations are type-annotated with their possible effects. Examples: Haskell, Idris, Ur/Web.
- i_s 11y agoPretty strange that you put Clojure in the "anything goes" category when it has been the clear leader when it comes to immutability. Lots of those languages you put in the other categories don't even have persistent data structures in their standard library.
- catnaroek 11y agoHere is why: http://pastebin.com/t3Q3CW4j http://pastebin.com/t3Q3CW4j This is particularly infuriating because the proper way to handle bound variables is already known: https://en.wikipedia.org/wiki/De_Bruijn_index https://en.wikipedia.org/wiki/De_Bruijn_index .
- i_s 11y agoNo one is maintaining state by constantly clobbering namespace level variables in Clojure, though. What actually comes into play are ways the language and standard library encourages passing data around and manipulating it, which in Clojure is as immutable as you'll find in any language.
- catnaroek 11y agoClojure encourages me to program in the REPL, because there is no other way to know what is going on in such a semantically crazy language, other than trial and error. And the state of the Clojure REPL is as mutable and imperative as it gets, as my paste showed.
- greydius 11y agoYou can rebind variables in ghci, too. I certainly wouldn't say this is evidence that Haskell promotes mutable data.
- catnaroek 11y ago> You can rebind variables in ghci No, you can't: http://pastebin.com/SdbKM7V7 http://pastebin.com/SdbKM7V7 In ML and Haskell, a new variable might shadow an old one (if they have the same name), but they are still different variables. Shadowing is slightly harder to implement than rebinding, but it provides a useful guarantee for the user: the meaning of existing definitions remains stable even if new definitions are introduced into the environment.