GHC Bug or User Error?

Brent Yorgey byorgey at
Mon Dec 7 01:10:27 EST 2009

On Sun, Dec 06, 2009 at 10:57:58PM -0600, Zachary Turner wrote:
> GHCi, version 6.10.4:  :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer ... linking ... done.
> Loading package base ... linking ... done.
> Prelude> let f x = x*x
> Prelude> let g x y = x+y
> Prelude> let q x y = (f . g) x y
> Prelude> :t q
> q :: (Num (a -> a), Num a) => a -> a -> a
> I'm somewhat of a beginner so the error could definitely be my own, but it
> seems to me like the third line should be rejected by GHCi.  As for the 4th
> line, the type of q seems nonsensical to me.  I can't figure out any
> possible valid meaning of 'Num (a -> a) '.

The last line is the key: all this code is perfectly valid, *as long
as* there is an instance of Num for the type a -> a.  (If you want
more careful explanation of how this works, let me know.)  There is no
such instance in the standard libraries, but type classes are open, so
you could always add such an instance yourself (although you are right
that this probably wouldn't make much sense); hence GHC cannot reject
the code.

GHC isn't perfect, but it's fairly polished and you're not likely to
stumble across a bug so easily. =) In the future you'll probably have
more luck sending questions to beginners at or
haskell-cafe at; or come by the #haskell IRC channel on


More information about the Glasgow-haskell-users mailing list