It is lectures by John Hugues. I implement the examples shown in his presentation. There are some codes he didn't give audiences, which are written by me to make project work.
Preliminaries are in file src/Tree.hs
, where a full binary tree are defined. We want solve two problems:
- number the leaves on a given tree
- zip two trees when trees have the same shape, otherwise return an "failed" result.
It is shown in file src/Tree/Naive.hs
, which is tedious and mistakable, because Haskell is pure and impossible to store variables during computions so that we need pass paramemters everywhere.
It is in file src/Tree/BeforeMonad.hs
and directory src/Tree/BeforeMonad
.
Here we get some common features in solutions of two problems. That is why we need monad, which defined by our discovered features.
In file src/Tree/Monad.hs
, we define Monad
class. The solutions to two problems are refactored using Monad
.
It file src/Tree/AfterMonad.hs
, some common operations for monad such as liftM2
and liftM
are defined, which makes our solutions shorter and more readable.
To generate a list of numbers, the seed
should be modified (next
or split
) and transmitted repeatedly.
Monad is boxed computions. IO is computions that interact with real world. In src/IO.hs
, the code shows that IO is something like RealWorld -> (RealWorld, feedback)
. It takes a "world" to get a new "world".
Nested lists isomorphic with trees. Lazy evaluation on nested lists is equivalent to deep first search on solution space tree.
Add features of state monad to any other monads.
A monad with features from both state and list.
A Haskell function appendL
behaves in the same way as Prolog function:
append([], Ys, Ys).
append([X|Xs], Ys, [Z|Zs]) :-
append(Xs, Ys, Zs)