Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
A D0L is a deterministic, context-free L-system.
An L-system is a tuple L = (V, ω, P) where
- V is the alphabet
- ω is the axiom (starting state)
- P is the set of rules
A deterministic L-system is one where there is only one production rule for each letter in the alphabet. A context-free L-system is one where the production rule looks only at the given letter, not at any of its neighbors.
Here, V is given by the inhabitants of a
, ω by an m
-container
of a
, and P by a Kleisli arrow a -> m a
. When m
is []
, this
is the usual notion of an L-system.
The original L-system used to model the growth of algae can be given by
data Algae = A | B deriving Show algae :: D0L [] Algae algae = D0L rules [B] where rules A = [A,B] rules B = [A]
We can demonstrate that the lengths of the generated strings give the fibonacci sequence:
>>>
print . map (length . axiom) . take 7 . generate $ algae
[1,1,2,3,5,8,13]