[Haskell-beginners] Maybe a and Maybe t

Daniel Fischer daniel.is.fischer at web.de
Sun May 31 11:42:44 EDT 2009


Am Sonntag 31 Mai 2009 15:37:27 schrieb Ivan Uemlianin:
> Dear Andrew and Lee
>
> Thanks for your comments.
>
> Andrew Wagner wrote:
> > As for why it actually happens in this case, it's no doubt related to
> > the particular algorithm ghci uses to do the type inference.

In particular the part where GHC assigns names to type variables.

>
> Interesting.  I tried it in hugs and it doesn't happen:
>
>   Main> :type safeSecond
>   safeSecond :: [a] -> Maybe a
>   Main> :type tidySecond
>   tidySecond :: [a] -> Maybe a
>   Main>
>
> So, it's a property of the ghci interpreter rather than of the language
> itself.

Yes.

>
> Just out of curiousity, I'd be interested to know what's going on in
> ghci to produce this effect.  Are there different types of type variable?

There are type variables of different *kind*, e.g. in

class Functor f where
    fmap :: (a -> b) -> f a -> f b

a and b are type variables of kind * (the kind of ordinary types) and f is a type variable 
of kind (* -> *) (the kind of type constructors which take an ordinary type and produce 
another ordinary type, examples are [] and Maybe).

But that has nothing to do with the phenomenon, in the inferred type signatures of 
safeSecond and tidySecond, the 'a' resp. 't' are both type variables of kind *.
The only difference is that in one case the name supply delivered 'a' and in the other it 
delivered 't'.



More information about the Beginners mailing list