Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created May 14, 2021 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymorris/f9198c52864d6c488a287af9ae601ba3 to your computer and use it in GitHub Desktop.
Save tonymorris/f9198c52864d6c488a287af9ae601ba3 to your computer and use it in GitHub Desktop.
data LSystem a b =
LSystem
[a]
(a -> [b])
type LSystem' a =
LSystem a a
instance Functor (LSystem a) where
fmap k (LSystem a f) =
LSystem a (fmap (fmap k) f)
bind ::
LSystem a b
-> [b]
bind (LSystem a f) =
a >>= f
apply ::
LSystem' a
-> LSystem' a
apply (LSystem a f) =
LSystem (a >>= f) f
answer ::
LSystem a b
-> [[b]]
answer (LSystem a f) =
map f a
constant ::
[a]
-> [b]
-> LSystem a b
constant a =
LSystem a . const
empty ::
LSystem a b
empty =
constant [] []
axiom ::
Functor f =>
([a] -> f [a])
-> LSystem a b
-> f (LSystem a b)
axiom k (LSystem a f) =
fmap (\a' -> LSystem a' f) (k a)
axioms ::
Applicative f =>
(a -> f a)
-> LSystem a b
-> f (LSystem a b)
axioms =
axiom . traverse
rule ::
Functor f =>
((a -> [b]) -> f (a -> [b]))
-> LSystem a b
-> f (LSystem a b)
rule k (LSystem a f) =
fmap (\f' -> LSystem a f') (k f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment