> > > > (3) OK with GHC, error with Hugs:
> > > >
> > > > f = \x -> m x
> > > > x = f()
> > > ...
> > > > - Is GHC's treatment of (3) a bug?
[..]
> > GHC is correct, because f *is* monomorphic: the only use is at type ().
> Thus f is given the
> >type () -> (), rather than C a => a -> (), and thus no sharing is lost.
> However, detecting
> > that f is only used at the one type involves sneaky look-ahead.
>
> Are you sure about this ? In my opinion the behaviour of Hugs is correct.
> It is clear that the use of "f" in the definition of "x" is monomorphic but
> that doesn't make true that "f" is monomorphic. I might import this module
> and use
> "f" at different types. In general I can only tell if a certain function is
> used at only one
> type if I either can see all the program code or if the scope of "f" is
> restricted
> to for example the current module.
>From sec 4.5.5 of the Haskell report:
"Rule 2 is required because there is no way to enforce monomorphic use
of an *exported* binding, except by performing type inference on
modules outside the current module. Rule 2 states that the exact types
of all the variables bound in a module must be determined by that
module alone, and not by any modules that import it."
f is required to be monomorphic by the Monomorphism Restriction, since
it is bound by a "simple pattern binding", i.e., f = e . Such
bindings can only be polymorphic if a type signature is given.
--KW 8-)
>
> -- Daan.
>
>
--
: Keith Wansbrough, MSc, BSc(Hons) (Auckland) ------------------------:
: PhD Student, Computer Laboratory, University of Cambridge, England. :
: (and recently of the University of Glasgow, Scotland. [><] ) :
: Native of Antipodean Auckland, New Zealand: 174d47' E, 36d55' S. :
: http://www.cl.cam.ac.uk/users/kw217/ mailto:[EMAIL PROTECTED] :
:---------------------------------------------------------------------: