[Haskell-beginners] what type is 'Val 9' when 'Val Int' a ctor
for 'Expr e'?
Daniel Fischer
daniel.is.fischer at web.de
Wed Oct 22 20:52:39 EDT 2008
Am Mittwoch, 22. Oktober 2008 23:44 schrieb Antoine Latter:
> On Wed, Oct 22, 2008 at 4:10 PM, Jason Dusek <jason.dusek at gmail.com> wrote:
> > Can you explain why you think you need that annotation? I
> > can't see an ambiguous interpretation of your code.
>
> The confusion is that the 'Val' constructor is for the 'Expr' type,
> which has a phantom type parameter in its type constructor.
>
> Can you load that up into GHCi and type:
> > :t val_9
>
> which should cause GHCi to print out what it thinks the type of that
> expression is.
>
> -Antoine
ghci correctly thinks that has the type Expr e. Much like
*Main> :t []
[] :: [a]
I think what goes on here is defaulting (deviating from Section 4.3.4 of the
report, but it's the same deviation that allows [] to be printed). To print
it, ghci picks some default type for e, probably Integer, as the defaut
default is (Integer, Double), doesn't influence the result of show.
If you muck around with the Show instance, you can easily get compilation
errors like "Ambiguous type variable..." (e.g. if you add a (Show e)
constraint to the Show instance for (Expr e), but not if you add a (Num e) or
an (Integral e) constraint).
More information about the Beginners
mailing list