[Haskell-cafe] Re: Rank-2-polymorphism problem
Martin Huschenbett
huschi at gmx.org
Sat Mar 24 07:24:46 EDT 2007
Martin Huschenbett schrieb:
> My thoughts were that for any class C the types
>
> > Maybe (forall a. C a => a) (I will call it T1 for short)
>
> and
>
> > (forall a. C a => Maybe a) (I will call it T2 for short)
>
> are isomorphic. Defining the isomorphism from T1 to T2 is quite simple:
>
> iso1 :: Maybe (forall a. C a => a) -> (forall a. C a => Maybe a)
> iso1 (Just s) = Just s
> iso1 Nothing = Nothing
>
> But I don't catch how to define the isomorphism of the other direction
> (from T2 to T1). I would guess that defining this isomorphism would also
> solve my problem concerning the SQL stuff.
I found the solution to my problem. I just want to post it for others
who may come across the same problem.
The trick was simply looking at GHC's error message that tells something
about ambiguous types. So let T be an arbitrary instance of C then the
other isomorphism becomes:
> iso2 :: (forall a. C a => Maybe a) -> Maybe (forall a. C a => a)
> iso2 s if isJust (s :: Maybe T) then Just (fromJust s) else Nothing
Regards,
Martin.
More information about the Haskell-Cafe
mailing list