3 ms·
As a long-time Lisper in AI, Haskell does look intriguing, but I'm more worried about what I would lose. In particular, I'm curious about how DSLs fare in Haske
by ced 12y ago
As a long-time Lisper in AI, Haskell does look intriguing, but I'm more worried about what I would lose. In particular, I'm curious about how DSLs fare in Haskell. I can write first-order logic sentences in Lisp, and they look and behave just like any other Lisp code. I can use evolutionary programming to generate new code on the fly, and send it to the compiler. And I can get really down to the metal if I ever need C-level performance.
How do these look in Haskell?
- gamegoblin 12y agoMonad do-notation makes domain specific languages pretty easy to implement.
- gizmo686 12y agoI've never learned Lisp, but my motivation for learning Haskell (after briefly toying around with it) was to create a DSL. Specifically, I was designing a DSL with the intention of implementing it in python, when I realized that my DSL seemed a lot like a monad in do notation. Implementing it didn't fail to dissapoint in just how easy it was. Having said that, a DSL implemented as a monad does not behave like any other haskell code, in that it is a monad, and only looks like a DSL when used in do notation.
- mietek 12y agoHaskell is great for DSLs. Some loose thoughts: - The syntax is clean and extensible. (Function application is `f(x)` in C, `(f x)` in Lisp, and `f x` in Haskell.) - The core language is small, with a suprising amount of functionality implemented as library functions. (Not surprising to a Lisp programmer, though.) - You can define your own infix operators, specify their precedence, and their fixity. (Left, like most mathematical operators, or right, like the exponentiation operator). - Because of Haskell's lazy evaluation, there is no distinction between special and non-special forms, so you don't need macros to build up syntactic sugar for your DSL. (Special forms, such as the C short-circuiting operators `&&` and `||`, only evaluate as much as is necessary, which is what Haskell does across the board.) - But if you really want macros or quasi-quotation, they're part of the language. (Macros are named Template Haskell.) - There is also built-in syntactic sugar which can be re-used for your own instances of common program patterns, such as monadic do-notation, monadic comprehensions, and arrows. There are many examples of Haskell DSLs online. A particularly amusing one is Lennart Augustsson's embedding of BASIC in Haskell, proving beyond all doubt that Haskell is in fact an imperative language, and all this talk about purity is poppycock. [1] [2] Haskell is also great for performance. GHC 7.8.2 is now ready to use, with the Mio high-performance multicore IO manager merged in. [3] The composable nature of Haskell also lends itself to surprisingly powerful optimisations. [4] Now, generating code at runtime and integrating it (interpreted, or even compiled) into the running image is definitely a strength of Lisp, and other under-appreciated artefacts of a future past, such as Smalltalk. I do not know how Haskell fares in this area, but I would like to find out. [1]: http://augustss.blogspot.co.uk/2009/02/regression-they-say-that-as-you-get.html http://augustss.blogspot.co.uk/2009/02/regression-they-say-t... [2]: http://augustss.blogspot.co.uk/2009/02/more-basic-not-that-anybody-should-care.html http://augustss.blogspot.co.uk/2009/02/more-basic-not-that-a... [3]: http://haskell.cs.yale.edu/wp-content/uploads/2013/08/hask035-voellmy.pdf http://haskell.cs.yale.edu/wp-content/uploads/2013/08/hask03... [4]: http://research.microsoft.com/en-us/um/people/simonpj/papers/ndp/haskell-beats-C.pdf http://research.microsoft.com/en-us/um/people/simonpj/papers...
- chrisdone 12y agoAs a Lisper who moved to Haskell, you will find Haskell lacking without template-haskell. With TemplateHaskell turned on, you can do the equivalent of quasi-quotes and reader macros: http://chrisdone.com/posts/common-lisp-haskell http://chrisdone.com/posts/common-lisp-haskell But regular, syntax-extending macros aren't possible. E.g. you can't write AIF, there is only quasiquotation. But if you're just worried about DSLs, then that is indeed possible. There's a culture of avoiding template-haskell in favour of using combinators, so you will sometimes have to stomach ugly DSLs with awful operators and silly names. On the other hand lazy functions are like compiler macros, so they compose better than Lisp macros, which generally compose horribly.