[Haskell-cafe] "Rebox Package" or "To Hackage or not to Hackage"
Holger Siegel
holgersiegel74 at yahoo.de
Tue Dec 8 16:55:11 EST 2009
Am Dienstag, den 08.12.2009, 23:25 +0200 schrieb Vitaliy Akimov:
> Hi John,
>
> I don't know if this is useful for you, but these are instances of
> Cofunctor's comap. For example if we use TypeCompose package we have:
>
> rebox f = unFlip . cofmap f . Flip
>
> The rest are also Cofunctors. There are a few options. You can either
> specify instances or use type combinators from category-extras or
> TypeCompose packages. Basically (a -> a -> b) is curried composition
> of diagonal Functor from Bifunctor (,) and Cofunctor (Flip (->) a)
> etc.
You can also define them recursively:
rebox0 :: (a -> b) -> c -> c
rebox0 _ x = x
reboxN :: ((a -> b) -> d -> e) -> (a -> b) -> (b -> d) -> a -> e
reboxN reboxM un re = reboxM un . re . un
rebox1 :: (a -> b) -> (b -> c) -> a -> c
rebox1 = reboxN rebox0
rebox2 :: (a -> b) -> (b -> b -> c) -> a -> a -> c
rebox2 = reboxN rebox1
rebox3 :: (a -> b) -> (b -> b -> b -> c) -> a -> a -> a -> c
rebox3 = reboxN rebox2
rebox4 = reboxN rebox3
rebox5 = reboxN rebox4
More information about the Haskell-Cafe
mailing list