Overloaded function and implicit parameter passing

Jeffrey R. Lewis jeff@galconn.com
Fri, 27 Oct 2000 08:10:29 -0700


José Romildo Malaquias wrote:

> Hi.
>
> While experimenting with the implicit parameter
> extension to Haskell 98, implemented in GHC 4.08.1
> and latest Hugs, I came accross a difference among
> those implementations regarding overloading functions
> with implicit parameters.
>
> As a test consider the program
>
> ------------------------- cut here
> module Main where
>
> class C a where
>     f :: (?env :: Integer) => a -> Integer
>
> instance C Integer where
>     f x = ?env + x
>
> main = putStrLn (show (f (45::Integer) with ?env = 100))
> ------------------------- cut here
>
> Hugs accepts this program and outputs 145, as expected.
> But GHC 4.08.1 refuses to compile it, emitting the
> message
>
> $ ghc -fglasgow-exts Test1.hs -o test1
>
> Test1.hs:7:
>     Unbound implicit parameter `env_rJX :: Integer'
>     arising from use of `env_rJX' at Test1.hs:7
>     In the first argument of `+', namely `env_rJX'
>     In the right-hand side of an equation for `f': env_rJX + x
>
> Compilation had errors
>
> Would anybody comment on what is going on with GHC?
>
> I am willing to use implicit parameters in the
> software I am developing, but I have the need
> to overload functions with implicit parameters.
> While Hugs is good for development, its performance
> may rule it out when the final product is ready.
> So I will need a good Haskell compiler to compile
> my system.
>
> Any comments?

Certainly a bug.  I'll look at it when I get a chance.

--Jeff