[Haskell-cafe] type keeping rounding, typeable (and a difficulty)

John Meacham john at repetae.net
Thu Nov 23 17:20:04 EST 2006

On Thu, Nov 16, 2006 at 10:44:59PM +0200, isto wrote:
> I'll guess the reason it didn't compile was different
> types at case branches (am I wrong?) Anyhow, do you know that 
> is it possible to choose the return type somehow in the spirit 
> above?  

GADTs let you do this. And they even omit the run time type check. though, the type class solution is the correct way to
do this sort of thing.

data Value a where
   IntLike :: Int -> Value Int
   CharLike :: Char -> Value Char

f :: Value a -> a
f x = case x of
   IntLike x -> x + 1
   CharLike x -> x:" plus one"

there is also Data.Dynamic and existential types which are related to
the task. 

John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list