category-theory-presentation/categories/30_How/300_Catamorphisms/070_morphism_Finally_length.md
2013-02-28 16:49:12 +01:00

376 B

κατα-morphism: Finally length

All needed information for making length.

instance Functor (StrF a) =
	fmap f (Cons c x) = Cons c (f x)
	fmap _ Nil = Nil

length' :: Str -> Int
length' = cata phi where
	phi :: Algebra StrF Int -- StrF Int -> Int
	phi (Cons a b) = 1 + b
	phi Nil = 0

main = do
	l <- length' $ stringToStr "Toto"
	...