Skip to content

Instantly share code, notes, and snippets.

@giuliohome
Created August 7, 2018 14:56
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 giuliohome/bfafafa5ebb9d9357a0a663c8646cd2b to your computer and use it in GitHub Desktop.
Save giuliohome/bfafafa5ebb9d9357a0a663c8646cd2b to your computer and use it in GitHub Desktop.
from wikipedia Catamorphism
type StepAlgebra b = (b, b->b) -- the algebras, which we encode as pairs (nil, next)
data Nat = Zero | Succ Nat -- which is the initial algebra for the functor described above
foldSteps :: StepAlgebra b -> (Nat -> b) -- the catamorphisms map from Nat to b
foldSteps (nil, next) Zero = nil
foldSteps (nil, next) (Succ nat) = next $ foldSteps (nil, next) nat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment