[Haskell-cafe] Scrap your rolls/unrolls
Sebastian Fischer
fischer at nii.ac.jp
Sat Oct 23 07:27:58 EDT 2010
Hi Max,
neat idea! Haskell supports laziness even on the type level ;)
I tried to play with your code but did not get very far. I quickly ran
into two problems.
On Oct 22, 2010, at 7:37 PM, Max Bolingbroke wrote:
> The annoying part of this exercise is the the presence of a "Force" in
> the functor definition (e.g ListF) means that you can't make them into
> actual Functor instances! The fmap definition gives you a function of
> type (a -> b) and you need one of type (Force a -> Force b). However,
> you can make them into a category-extras:Control.Functor.QFunctor
> instance
I think `Control.Functor.Categorical.CFunctor` is a more natural
replacement for functor here. One can define
instance CFunctor (ListF a) ForceCat Hask
and I was hoping that I could define `fold` based on CFunctor but I
did not succeed. The usual definition of `fold` is
fold :: Functor f => (f a -> a) -> Fix f -> a
fold f = f . fmap (fold f)
and I tried to replace this with
fold :: CFunctor f ForceCat Hask => ...
but did not find a combination of type signature and definition that
compiled.
My second problem came up when writing a `Show` instance for the
`List` type. This works:
instance Show a => Show (List a) where
show Nil = "Nil"
show (Cons x xs) = "(Cons " ++ show x ++ " " ++ show xs ++ ")"
But trying to avoid TypeSynonymInstances leads to a non-terminating
`show` function:
instance (Show a, Show (Force rec)) => Show (ListF a rec) where
show Nil = "Nil"
show (Cons x xs) = "(Cons " ++ show x ++ " " ++ show xs ++ ")"
Shouldn't both work?
Sebastian
More information about the Haskell-Cafe
mailing list