[Haskell-cafe] A voyage of undiscovery

John Meacham john at repetae.net
Thu Jul 16 20:05:32 EDT 2009


On Thu, Jul 16, 2009 at 08:52:40PM +0100, Andrew Coppin wrote:
> Ross Mellgren wrote:
>> It's not where -- let also works
>>
>> Prelude> let { foo x = x } in (foo 1, foo True)
>> (1,True)
>
> Awesome. So by attempting to implement Haskell's type system, I have  
> discovered that I actually don't understand Haskell's type system. Who'd  
> have thought it?
>
> Clearly I must go consult the Report and check precisely what the rules  
> are...


actually, the rules are pretty straightforward. It doesn't matter where
something is bound, just _how_ it is bound. Let-bound names (which
includes 'where' and top-level definitions) can be polymorphic.
lambda-bound or case-bound names (names bound as an argument to a
function or that appear in a pattern) can only be monomorphic. And
that's all there is to it. (the monomorphism restriction complicates it
a little, but we don't need to worry about that for now)

As an extension, ghc and jhc allow arguments and case bound variables to
be polymorphic but only when explicitly declared so by a user supplied
type annotation. (the exact rules for what 'explicitly declared' means
can be a little complicated when formalized, but they match up enough
with intuition that it isn't a problem in practice). They will never
infer such a type on their own.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/


More information about the Haskell-Cafe mailing list