1 | chewie.hs
The Hello, World! of Haskell. - Compile with Haskell compiler ghc via
ghc --make chewie.hs , execute on the command line with ./chewie . - Load into REPL ghci via
ghci chewie.hs , then evaluate function main .
|  |
2 | isPrime.hs
Prime number test. Efficient thanks to lazy evaluation of factors (a comparison with the empty list [] can be decided once the first element of factors has been found). |  |
3 | infix-op.hs
Demonstrates the definition of user-defined operator ~=~ . |  |
4 | factorial.hs
Compute the factorial n! of natural number n. Defines two equivalent variants of the function that demonstrate the use of conditional expressions (if...then...else... ) and guards. |  |
5 | power.hs
Two equivalent formulations of an efficient power computation.
Demonstrates the use of guards, local definitions (where , let … in ) and explicit layout syntax using { ,} and; . |  |
6 | bits.hs
A demonstration of type synonyms (type t₁ = t₂ ) and list processing (determine the bit list of an Integer value). |  |
7 | sum.hs
A reimplementation of the sum built-in function: sum all elements of a list. Two formulations: guards and pattern matching. |  |
8 | take.hs
A reimplementation of the built-in take function: extract a prefix (of given length) from a list. |  |
9 | mergesort.hs
An implementation of MergeSort in Haskell. Builds on the merge function developed in the lecture. |  |
10 | deriving.hs
Definition of and functions over sum data types (Weekday , Move , Outcome ). Uses deriving to define basic operations like equality, ordering, showing, ... |  |
11 | sequence.hs
Definition and functions over product type Sequence . |  |
12 | cons.hs
Defines algebraic data type List a and shows that it is isomorphic to the builtin type constructor [a] . Uses lifting to lift regular list-processing functions from [a] to List a . |  |
13 | eval-compile-run.hs
Defines abstract syntax trees for simple arithmetic expressions Exp a and implements an interpreter (≡ evaluation function eval ), compiler (compile ) and mini stack-based virtual machine (run ). Interpreter as well as compiler and VM are related: ∀ e :: Num a => Exp a: (run [] . compile) e == eval e
|  |
14 | searchFor.hs
Function searchFor performs a lookup in a key/value-dictionary, provided that the key type supports equality comparisons. (An equivalent function is already built into Haskell's Prelude: lookup .) |  |
15 | library-exposed.hs
First version of the IntegerSet DSL with fully exposed implementation details. 🙁 |  |
16 | set-language-shallow.hs
Imports module SetLanguageShallow (or SetLanguageShallowCard ) to demonstrate that representation details remain hidden. |  |
17 | SetLanguageShallow.hs (module)
Re-implementation of the IntegerSet DSL with representation details (characteristic functions with type Integer -> Bool ) hidden inside a module. Module is imported by set-language-shallow.hs . |  |
18 | SetLanguageShallowCard.hs (module)
A shallow embedding of IntegerSet based on characteristic functions. This module includes a cardinality observer for sets. |  |
19 | set-language-deep.hs
Imports module SetLanguageDeep (or SetLanguageDeepCard ) to demonstrate a deep embedding of the integer set DSL. |  |
20 | SetLanguageDeep.hs (module)
A deep embedding of IntegerSet . |  |
21 | SetLanguageDeepCard.hs (module)
A deep embedding of IntegerSet . This module includes a cardinality observer for sets. |  |
22 | ExprDeep.hs (module)
A simple deeply embedded DSL over values of type Integer and Bool . Permits the construction of il-typed expressions. |  |
23 | expr-language.hs
Imports module ExprDeep and builds one well-typed and one ill-typed expression. |  |
24 | ExprDeepGADTTyped.hs (module)
Uses GADTs to define a deeply embedded DSL over Integer and Bool values that detects ill-typed expressions at compile time. |  |
25 | expr-language-typed.hs
Imports module ExprDeepGADTTyped and demonstrates the well-typed construction and evaluation of expressions. |  |
26 | ExprEmbeddings.hs
Define type class Expr a that describes a simple language over Integer s with let...in -bindings. Three instances of this class define two shallow and one deep embedding of this language. [ Additional material — not discussed in the lecture. ] |  |
27 | expr-embeddings.hs
Imports module ExprEmbeddings to test all three instances of the Expr a language. [ Additional material — not discussed in the lecture. ] |  |
28 | PatternMatching.hs
Defines a DSL that describes string patterns. Pattern matching returns (a possible empty) list of matches: type Pattern a = String -> [(a, String)]
↑ ↑ ↑
input result residual string
|  |
29 | pattern-matching.hs
Imports module PatternMatching to test-drive the pattern matchers. |  |
30 | normal-order.hs
Demonstrates that normal order reduction finds the normal form of an expression regardless of the presence of undefined values (function bomb has value ⊥). |  |
31 | sharing.hs
Uses trace (module Debug.Trace ) to demonstrate that Haskell employs graph reduction (redex sharing) during evaluation. |  |
32 | bottom.hs
Demonstrates the strict semantics of pattern matching in Haskell. |  |
33 | min=head-isort.hs
Implements list minimum as the composition head . isort to demonstrate that lazy evaluation (to WHNF) can make declarative specifications of algorithms efficient to execute. Caveat: this depends on the interaction of head and isort and does not work for arbitrary sorting algorithms. |  |
34 | newton-raphson.hs
Modular program whose parts communicate via infinite lists. Approximate the square root of x using the Newton-Raphson series. Composes iterate with within , where the latter inspects a finite prefix of the potentially infinite list generated by the former. Haskell's evaluation to WHNF glues both together so that a result is produced in finite time. |  |
35 | numerical-integration.hs
Modular program whose parts communicate via infinite lists. Approximate the square of function f within interval [x₁,x₂]. Divide the interval until f is close to linear in the subdivision. Keep subdividing until the sum of subdivided integrals converges. Interval subdivision (subdivide ) keeps generating new integral approximations until test within decides that we have reached the desired accuracy. |  |
36 | flagged-status.hs
Demonstrates the use of partially applied binary type constructors to form new unary type constructors: type Flagged = (,) Bool
|  |
37 | round.hs
Builds on the fact that Either String is an instance of Functor to build a composition of functions that propagates error messages. |  |
38 | stacked-functors.hs
Use a growing chain of fmap compositions to "reach into" and manipulate a complex value at desired depth in a nested value build out of functors. |  |
39 | break-the-law.hs
Defines a Functor instance for an algebraic data type (a deeply embedded DSL over Booelans) and demonstrates that functor laws are satisfied/violated when we get the implementation of fmap right/wrong. |  |
40 | apples-oranges-newtypes.hs
Use Haskell's newtype to create specific variants of existing types. No runtime overhead! |  |
41 | Validation.hs
(Module) Represent computations that are accompanied with an error context. Defines Functor and Applicative instances. |  |
42 | validate.hs
Uses module Validation.hs to perform username/password validation that is not cluttered with error log accumulation. |  |
43 | sequence-Maybe.hs
Defines the (>=>) left-to-right composition operator (Kleisli composition) for partial functions of type a -> Maybe b and puts that to use. |  |
44 | sequence-Either.hs
Defines the (>=>) left-to-right composition operator (Kleisli composition) for exception-generating functions of type a -> Exc b ≡ a -> Either Error b and puts that to use. |  |
45 | sequence-ST.hs
Defines the (>=>) left-to-right composition operator (Kleisli composition) for stateful functions of type a -> ST b ≡ a -> State -> (State, b) and puts that to use. |  |
46 | monadic-Maybe.hs
Define a composition based on partial functions a -> Maybe b based on the Monad instance for Maybe . Sequencing is based on monadic bind ((>>=) ). Compare this to file sequence-Maybe.hs . |  |
47 | monadic-Either.hs
Composition of exception-generating functions (data types Either or Exc ) in monadic style (using >>= ). |  |
48 | monadic-ST-newtype.hs
Composition of state-transforming functions in monadic style. As is idiomatic in modern Haskell, the state transformer is defined using newtype . |  |
49 | monadic-do-NonDet.hs
Composition of non-deterministic functions in monadic style, using do -notation. |  |
50 | copyFile-error.hs
Interactive file copying program running in the IO monad. Non-existing source files are detected before copying starts. |  |
51 | copyFile-ignore.hs
Interactive file copying program running in the IO monad. Demonstrates that the construction of an I/O action and its execution are separate things. ignore receives the constructed I/O action but discards it such that it is never executed. |  |
52 | IOaction.hs
Demonstrates the separation of - the pure construction of complex IO actions (type
IOaction a ) and - the effectful execution of the constructed actions.
Construction uses monadic style to synthesize complex IO actions. A complex action essentially is a value of the algebraic data type IOaction a , i.e., an abstract syntax tree that describes a side-effectful program. Execution of the program is performed by Haskell's runtime system once function main returns the abstract syntax tree as its result. |  |
53 | monad-trans-1.hs
Using monad transformers to combine monads Either and IO . Step ➊: Simple computation that may fail (no I/O yet). |  |
54 | monad-trans-2.hs
Using monad transformers to combine monads Either and IO . Step ➋: A mix of Either and IO computations leads to ugly nesting (see function userLogin ). |  |
55 | monad-trans-3.hs
Using monad transformers to combine monads Either and IO . Steps ➌ + ➍: Define a new monad EitherIO whose >>= operator combines I/O and exception handling. |  |
56 | monad-trans-4.hs
Using monad transformers to combine monads Either and IO . Step ➎: Add exception handling via throw and catch to model complex application behavior (see function loginDialogue ). |  |
57 | monad-trans-5.hs
Using monad transformers to combine Either and arbitrary monad m. Generalize EitherIO e a to EitherT e m a that combines Either with any other monad m . Also see Haskell's library transformers of monad transformers, in particular Control.Monad.Trans.ExceptT . |  |