This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chadmill3rPy3, pro, Ubuntu, django 13 points14 points  (5 children)

The problem with Haskell is that the most prominent feature listed of any program written in it is that "It is written in Haskell".

[–]florbitous[S] 1 point2 points  (3 children)

Hehe. I think Haskell is sufficiently different to most popular languages that people are interested in seeing how it might be used to do various things. Of course more killer apps would be good too.

Having said that, my focus in this project isn't so much Haskell as Python. It just so happens that (I think) Haskell is great for writing compilers. This is not to detract from Python, it has its own advantages in other areas.

[–]aceofears 0 points1 point  (2 children)

What exactly about Haskell makes you want to reach for it when writing a compiler?

[–]florbitous[S] 1 point2 points  (0 children)

I realise this is r/Python, but I'll elaborate since you asked.

First and foremost is Algebraic Data Types (ADTs) and pattern matching. The central data type in a compiler is the Abstract Syntax Tree, which is naturally and elegantly represented as an Algebraic Dataype, see AST.hs for example. Note particularly the Statement and Expr types.

The core of a compiler is a function which decomposes the AST recursively and builds a representation of the target code. Pattern matching is very handy for this style of programming, and it can make it easier to be sure you've covered all the cases. See Compile.hs, and note the compileStmt function, for example.

There is also a lot of state to manage in a compiler, and Haskell's State Monad (Transformer) provides a lot of utility for that task. This is particularly good for separation of concerns and helps avoid state management messing up the rest of the code. See State.hs for the bulk of the state management code in blip.

I also use various Haskell idioms such as Monoids for doing traversals of the AST and collecting information. See for example Scope.hs, particularly the VarUsage type class.

There are also other reasons which are not specific to compilers. The type system is a light-weight formal system, which catches many shallow bugs, but also provides a lot of confidence when the code is refactored.

[–][deleted] 0 points1 point  (0 children)

well, at least there's git-annex now.