type checking fails with a correct type

Jan Jakubuv jakubuv at gmail.com
Thu Apr 30 13:45:04 EDT 2009


Hello Daniel,

On Thu, Apr 30, 2009 at 05:17:42PM +0200, Daniel Fischer wrote:
> In
> 
> nonsense t = case nonsense t of
>                 Nothing -> Just empty
> 
> , which type has the Nothing? 
> It can have the type Maybe s1 for all s1 belonging to SUBST, that is the ambiguous type 
> variable.
> 

thanks for the explanation. Maybe I'm starting to understand what is going
on. Now I understand it thus the call of `nonsense` inside the case
construct can potentially result in a different `SUBST`-type `s1` than the
top-level `nonsense`. That is why it has to be explicitly typed.

But I am still not following why the type inference works fine without the
signature. Isn't it still ambiguous?

> 
> {-# LANGUAGE ScopedTypeVariables #-}
> 
> nonsense :: forall s. SUBST s => t -> Maybe s
> nonsense t = case nonsense t :: Maybe s of
>                 Nothing -> Just empty
> 

Great, ScopedTypeVariables is exactly what I was looking for. It solves all
my problems. 

Thank you,
  Jan.


-- 
Heriot-Watt University is a Scottish charity
registered under charity number SC000278.



More information about the Glasgow-haskell-users mailing list