Interaction and ambiguous type variables

Simon Peyton-Jones simonpj@microsoft.com
Thu, 3 Jul 2003 15:03:42 +0100


| > 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'.
|=20
| 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:
|=20
| > 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'.
|=20
| 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.

Good idea.  I'm fixing ghci to do this too, at least when there is a
Show class involved, and only standard classes (i.e. same rules as for
numerics, except that we add 'Show' to the list of classes that trigger
defaulting.)

Simon



_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs