Re: Interaction and ambiguous type variables

Malcolm Wallace <[email protected]>
Newsgroups gmane.comp.lang.haskell.glasgow.bugs,gmane.comp.lang.haskell.hugs.bugs
Organization Dept of Computer Science, University of York
Message-ID <[email protected]>
Ralf Hinze <[email protected]> writes:

> I am posting the following bug report every once in a while.
> 
> Main> mirror []
> ERROR - Cannot find "show" function for:
> *** Expression : mirror []
> *** Of type    : [a]
> 
> << Instructor:
> it's because `mirror []' has the polymorphic type `[a]' and the
> compiler cannot determine the `Show' instance for `a'.

It might be worth pointing out that, even though Hugs and ghci have
this problem, nhc98 (used interactively through 'hi') does not.  It
follows your suggested solution:

> The general problem is that the expression submitted to Hugs or GHC has a
> polymorphic type *or* that a subexpression has a polymorphic type (as
> in the last example). A simple solution is to monomorphize the type
> instantiating all type variables to, say, the empty type `Void'.

except that nhc98 uses the in-scope defaulting rule (e.g. default
(Integer)) to select an arbitrary dictionary to plug in, rather than
introducing a new type.  There are only rare cases in which the actual
dictionary matters, so this suffices for the beginner.

Regards,
    Malcolm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.