[Haskell-cafe] Re: Aren't type system extensions fun? [Further
analysis]
Andrew Coppin
andrewcoppin at btinternet.com
Wed May 28 15:03:21 EDT 2008
Roberto Zunino wrote:
> When you type some expression such as
>
> \x -> x
>
> you have to choose among an infinite number of valid types for it:
>
> Int -> Int
> Char -> Char
> forall a . a -> a
> forall a b . (a,b) -> (a,b)
> ...
>
> Yet the type inference is smart enough to choose the "best" one:
> forall a. a -> a
> because this is the "most general" type.
>
> Alas, for code like yours:
>
> foo = \f -> (f 'J', f True)
>
> there are infinite valid types too:
>
> (forall a. a -> Int) -> (Int, Int)
> (forall a. a -> Char)-> (Char, Char)
> (forall a. a -> (a,a)) -> ((Char,Char),(Bool,Bool))
> ...
>
> and it is much less clear if a "best", most general type exists at all.
> Requiring a type annotation for these not-so-common code snippets
> seems to be a fair compromise, at least to me.
Thank you for coming up with a clear and comprehensible answer.
More information about the Haskell-Cafe
mailing list