[Haskell-cafe] Re: [darcs-conflicts] how to nicely implement phantom type coersion?

Ian Lynagh igloo at earth.li
Thu Dec 8 09:35:24 EST 2005


On Thu, Dec 08, 2005 at 09:23:22AM -0500, David Roundy wrote:
> 
> data EqContext a b = EqContext { safe_coerce :: f(a,b) -> f(b,a) }
> 
> where f(a,b) is a function of two types that returns a type, so the value
> of f(a,b) might be (Patch a b) or (Patch x b) or something like that.
> 
> But I'm not sure if this is possible in Haskell, and if it is, then it
> definitely requires some sort of tricky extension that I'm not familiar
> with...

I'm a bit confused, but if you have:

sc :: p a b -> p a c
sc = unsafeCoerce#

then (with Either standing in for Patch, PatchList etc and some concrete
types as parameters to simplify things)

sc (undefined :: Either Int Char) :: Either Int Bool

is well-typed but

sc (undefined :: Either Int Char) :: Either String Char

isn't. Is that what you want?


Thanks
Ian



More information about the Haskell-Cafe mailing list