16 lines
466 B
HTML
16 lines
466 B
HTML
<h2 id="κατα-morphism-finally-length">κατα-morphism: Finally length</h2>
|
|
<p>All needed information for making length.</p>
|
|
<pre><code>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"
|
|
...</code></pre>
|