3 ms·
Haskell 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 Has
by mietek 12y ago
Haskell 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...