Allowing safe cast by default

Maciej Piechotka uzytkownik2 at
Sat Sep 5 17:06:47 EDT 2009

As far as I underspend all checks of Data.Typeable.cast can be done by
compiler in compile-time. 

While it impose partially what one may consider syntax sugar I believe
that there is no restriction that would not allowed compiler to behave
like that:

cast :: forall a b. a -> Maybe b
-- Pseudo-haskell
cast x = staticIf a == b then Just x else Nothing

Also I may not grasp every element of Haskell but what is the reason of
not implementing Typeable by default?


[1] You may say that I need unsafeCoerce but
1. I'd prefere to write

let x = fromMaybe (error "Wrong types") $ cast x' :: a

instead of

let x = unsafeCoerce x' :: a

in case when I (not compiler) know that x and x' have the same type (a)
as it makes the crash big and in Haskell instead of possible some
problems with GC or something which I'll find in totally unrelated piece
of program.
2. I may want different actions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url :

More information about the Haskell-prime mailing list