That's simple Tom. Imagine the factorial function for Int written as a paramorphism: type instance F Int = Either One instance (Mu Int) where inn (Left _) = 0 inn (Right n) = succ n out 0 = Left () out n = Right (pred n) instance Functor (F Int) where fmap _ (Left ()) = Left () fmap f (Right n) = Right (f n) fact :: Int -> Int fact = para (const 1 \/ (uncurry
Yes, I have tried both implementations at the start and solved it by choosing for the following: type family F a :: * -> * type FList a x = Either () (a,x) type instance F [a] = FList a instance (Functor (F [a])) where fmap _ (Left _) = Left () fmap f (Right (a,x)) = Right (a,f x) The option was: type family F a x :: * type instance F [a] x = Either() (a,x) instance (Functor (F
Oops; I totally forgot the context of this whole discussion! I enjoyed your article. On 2/12/07, Bernie Pope <bjpop@csse.unimelb.edu.au> wrote: Nicolas Frisby wrote: Guess this is a tricky choice for a foldr intro, since it requires a "paramorphism" (see bananas lenses wires etc.) para :: (a -> [a] -> b -> b) -> b -> [a] -> b para f e [] = e para f e (x:xs) =
Guess this is a tricky choice for a foldr intro, since it requires a "paramorphism" (see bananas lenses wires etc.) para :: (a -> [a] -> b -> b) -> b -> [a] -> b para f e [] = e para f e (x:xs) = f x xs (para f e xs) -- note that the original tail of the list (i.e. xs and not xs') is used in the else-branch dropWhile' p = para (\x xs xs' -> if p x then xs' else (x:xs)) [] Prelude> dropWhile'