25.10.2015 Views

Write You a Haskell Stephen Diehl

1kEcQTb

1kEcQTb

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Design of Proto<strong>Haskell</strong><br />

Now that we’ve completed our simple little ML language, let’s discuss the road ahead toward building a<br />

more complex language we’ll call Proto<strong>Haskell</strong> that will eventually become the full Fun language.<br />

Language Chapters Description<br />

Poly 1 - 8 Minimal type inferred ML-like language.<br />

Proto<strong>Haskell</strong> 8 - 18 Interpreted minimal <strong>Haskell</strong> subset.<br />

Fun 18 - 27 Proto<strong>Haskell</strong> with native code generator.<br />

e defining feature of Proto<strong>Haskell</strong> is that is independent of an evaluation model, so hypothetically<br />

one could write either a lazy or strict backend and use the same frontend.<br />

Before we launch into writing compiler passes let’s look at the overview of where we’re going, the scope<br />

of what we’re going to do, and what needs to be done to get there. We will refer to concepts that are not yet<br />

introduced, so keep is meant to be referred to as a high-level overview of the Proto<strong>Haskell</strong> compiler pipeline.<br />

<strong>Haskell</strong>: A Rich Language<br />

<strong>Haskell</strong> itself is a beautifully simple language at its core, although the implementation of GHC is arguably<br />

anything but simple! e more one digs into the implementation the more it becomes apparent that a<br />

lot of care and forethought was given to making the frontend language as expressive as it is. Many of<br />

these details require a great detail of engineering work to make them work as seamlessly as they do.<br />

Consider this simple <strong>Haskell</strong> example but note how much of an extension this is from our simple little<br />

ML interpreter.<br />

filter :: (a -> Bool) -> [a] -> [a]<br />

filter pred [] = []<br />

filter pred (x:xs)<br />

| pred x = x : filter pred xs<br />

| otherwise = filter pred xs<br />

Consider all the things that are going on just in this simple example.<br />

• Lazy evaluation<br />

• Custom datatypes<br />

104

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!