From 0ecbb8742382b41582214f4b57a95a64fb971bd5 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Sat, 21 Nov 2015 09:52:39 -0500 Subject: [PATCH] build environment --- .gitignore | 1 + 009_datatypes.md | 19 +++++++++++++++++++ README.md | 14 ++++++++++++++ chapter10/adt.hs | 8 ++++++++ index.md | 6 +----- write-you-a-haskell.cabal | 21 +++++++++++++++++++++ 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 chapter10/adt.hs create mode 100644 write-you-a-haskell.cabal diff --git a/.gitignore b/.gitignore index 4dc36c6..350368f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ includes *.html *.agdai *.history +Setup.hs diff --git a/009_datatypes.md b/009_datatypes.md index 190e52f..cf94427 100644 --- a/009_datatypes.md +++ b/009_datatypes.md @@ -4,6 +4,25 @@ Datatypes ========= +Algebraic data types +-------------------- + +**Algebraic datatypes** are a family of constructions arising out of two +operations, sums and products. A product encodes multiple arguments to +constructors and sums encode choice between constructors. + +```haskell +data Unit = Unit -- 1 +data Empty -- 0 +data (a * b) = Product a b -- a * b +data (a + b) = Inl a | Inr b -- a + b +data Exp a b = Exp (a -> b) -- a^b +data Rec f = Rec (f (Rec f)) -- \mu +``` + +Catamorphisms +------------- + Syntax ------ diff --git a/README.md b/README.md index 392b538..3e216c7 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,20 @@ Releases * Chapter 27: Row Polymorphism & Effect Typing * Chapter 28: Future Work +Building +-------- + +To generate the build scripts provision a cabal sandbox with pandoc in it. This +is done by the ``write-you-a-haskell.cabal`` file. + +```bash +$ cabal sandbox init +$ cabal install --only-dependencies +$ cabal exec bash +$ make +$ make pdf +``` + Contributing ------------ diff --git a/chapter10/adt.hs b/chapter10/adt.hs new file mode 100644 index 0000000..4dc26f5 --- /dev/null +++ b/chapter10/adt.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE TypeOperators #-} + +data Unit = Unit -- 1 +data Empty -- 0 +data (a * b) = Product a b -- a * b +data (a + b) = Inl a | Inr b -- a + b +data Exp a b = Exp (a -> b) -- a^b +data Rec f = Rec (f (Rec f)) -- diff --git a/index.md b/index.md index c8add2b..db413bc 100644 --- a/index.md +++ b/index.md @@ -55,11 +55,7 @@ lazy evaluation, interpreter, native code generator, a runtime, and several optimization passes. As with most of my writing, this is the pre-edited rough cut version, which I -will refine over time. The compiler itself is fully complete as of December -2014, but each of the chapters (28 in total) will be staggered on a -month-by-month basis to allow me to progressively refine the text with feedback -from readers and testers. The later chapters on runtime and code generation are -somewhat involved and much longer. +will refine over time. * [Chapter 1: Introduction](000_introduction.html) * [Chapter 2: Haskell Basics](001_basics.html) diff --git a/write-you-a-haskell.cabal b/write-you-a-haskell.cabal new file mode 100644 index 0000000..58499fd --- /dev/null +++ b/write-you-a-haskell.cabal @@ -0,0 +1,21 @@ +name: write-you-a-haskell +version: 0.1.0.0 +license: MIT +license-file: LICENSE +author: Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +build-type: Simple +extra-source-files: README.md +cabal-version: >=1.10 + +executable write-you-a-haskell + main-is: Main.hs + build-depends: + base >= 4.7 && <4.8, + pretty >= 1.1 && <1.2, + containers >= 0.5 && <0.6, + transformers >= 0.3 && <0.4, + haskeline >= 0.7 && <0.8, + pandoc -any + build-tools: alex, happy + default-language: Haskell2010