4 ms·
I'd say Monads are useful for encoding computation that ensures through type system that no data escapes wrapping; which can be used for tracking computations w
by iamnotsure 4y ago
I'd say Monads are useful for encoding computation that ensures through type system that no data escapes wrapping; which can be used for tracking computations with side effects but not only.
I am not sure about the Clojure macros vs Haskell monads, there are no macros in Haskell. Also, the article does not mention that Haskell is non-strict, while Clojure is strict, also static typing vs dynamic typing.
Those are very different languages and comparisons can be very misleading. Code is data is a LISP idiom expressed with S-expressions, I think in Haskell, code is code, data is data, which makes it less powerful for some use cases, but possibly more safe etc. I've heard about a different rite of a passage for Haskell programmers - contributing to GHC.
Clojure is a LISP dialect, basics of LISP are possibly eval, quote, lambda, apply; functions for meta-circular interpreter.
Haskell is a little different, but also functional paradigm, basics of Haskell are type system, algebraic data types, lazy evaluation, classes.
It is possible to emulate Monadic chaining in other languages; but static type system and lazy evaluation is a different matter.
- eru 4y ago> I am not sure about the Clojure macros vs Haskell monads, there are no macros in Haskell. Haskell has macros, they are just less prominent than in Lisps. There's even multiple approaches to macros in Haskell. One of them is template Haskell.
- iamnotsure 4y agoIsn't it about runtime macros vs compile time macros aka templates, Haskell has no runtime macros, LISP has them, I'd guess you can manipulate and redefine mostly everything in runtime in LISP, not so in Haskell?
- eru 4y agoHuh? Which Lisp has runtime macros? I am only aware of 'compile time' macros. I am most familiar with Scheme (and Racket) and Common Lisp. Could you explain how 'runtime macros' work in any of these systems? Perhaps give some example code?
- iamnotsure 4y agoI was thinking about the difference between templates in C++ or Haskell, which are kind of strictly compile time macro/code generation systems; vs macros in Scheme / Lisp, languages with self-contained compilers/interpreters, due to `eval` and `quote`, which are in basic case evaluated somewhat at runtime. C++ and Haskell do not have `eval`, at least not the early versions, not in the default language specification. So LISP/Scheme as a more dynamic, more runtime languages; C++/Haskell, more static, with compile time template facilities languages.
- shirogane86x 4y agoHaskell (at least as implemented in GHC) has TemplateHaskell, which is somewhat of an inbetween: at a distance it kinda resembles lisp macros if you squint a bit (it's of the "eval and quote" kind, so to say) but it's exclusively compile time. It's also quite unwieldy, and most of the time it ends up being unnecessary because Haskell can do things through other means. Laziness for control structures, Typeclasses with all the extensions for code generation... nowadays I only really see Template haskell used for two things: generating top level bindings that don't really belong in a type class (e.g.: singletons, lens, polysemy) or embedding of another language (yesod's hamlet, or some sql libraries). Haskell is not really built to support macros from the start, they're seen as more of a necessary evil, IMO. If you've used rust before, it's kinda like rust macros except worse :)
- iamnotsure 4y agoI am not sure if exclusively compile time `eval` is possible, by `eval` I mean `eval` that should handle I/O just fine. Such `eval` would make for compilation that possibly never ends.
- eru 4y agoOh, I think I would describe that as Lisp also being the language of its macro system. Whereas the language used in Template Haskell is not Haskell. Similarly to how the C preprocessor doesn't use C as its 'scripting language' but some weird unholy concoction. But that doesn't have much to do with being dynamic or 'runtime'. You could hack up a pre-processor for C that uses C. (It just would be unwieldy.) Btw, many Lisps are compiled. I don't think `eval` is necessary to make a Lisp; but it is indeed rather common.