GHC doesn't like its own type?

Erkok, Levent levent.erkok@intel.com
Wed, 30 Apr 2003 15:57:51 -0700


Sometimes ghc/hugs will reject a program when you provide a type signature
that it can deduce itself. This has been observed before: See Simon PJ's
message:

      http://www.mail-archive.com/haskell@haskell.org/msg06764.html

Of course, the "bus error" and the "panic" are truly GHC bugs, you might be
better off reporting them at:

      http://sourceforge.net/tracker/?group_id=8032&atid=108032

-Levent.

> -----Original Message-----
> From: oleg@pobox.com [mailto:oleg@pobox.com]
> Sent: Wednesday, April 30, 2003 3:48 PM
> To: haskell@haskell.org
> Subject: GHC doesn't like its own type?
> 
> 
> The previously message "Deeply uncurried products, as categorists
> might like them" can be used to demonstrate certain behavior of GHC
> that seems a bit odd. If we save the text of that message in a file,
> /tmp/a.lhs, we can load it into GHC:
> 
>   $ ghci -fglasgow-exts /tmp/a.lhs
>   GHC Interactive, version 5.04.1
>   Ok, modules loaded: Main.
>   *Main>
> 
> The whole code loads and typechecks. The code contains the following
> definition, without an explicit type signature:
> 
> > fcomp a = (. fapp) (mcomp a)
> 
> We can ask GHCi to tell us the type of fcomp:
> 
> 	*Main> :type fcomp
> 	forall result f1 a f2 c cp.
> 	(FApp a cp c, MCompose f2 cp c result) =>
> 	(f1 -> f2) -> a -> f1 -> result
> 
> and make that type, verbatim, to be the signature of fcomp:
> 
> > fcomp:: forall result f1 a f2 c cp. (FApp a cp c, MCompose f2 cp c
> result) => (f1 -> f2) -> a -> f1 -> result
> > fcomp a = (. fapp) (mcomp a)
> 
> If we reload the file, we get an error:
> 
> /tmp/a.lhs:124:
>     Could not deduce (FApp a cp c1)
>         from the context (FApp a cp c, MCompose f2 cp c result)
>     Probable fix:
>         Add (FApp a cp c1) to the type signature(s) for `fcomp'
>     arising from use of `fapp' at /tmp/a.lhs:124
>     In the second argument of `(.)', namely `fapp'
>     In the definition of `fcomp': (. fapp) (mcomp a)
> 
> /tmp/a.lhs:124:
>     Could not deduce (MCompose f2 cp c1 result)
>         from the context (FApp a cp c, MCompose f2 cp c result)
>     Probable fix:
>         Add (MCompose f2 cp c1 result) to the type signature(s) for
> `fcomp'
>     arising from use of `mcomp' at /tmp/a.lhs:124
>     In the first argument of `(. fapp)', namely `(mcomp a)'
>     In the definition of `fcomp': (. fapp) (mcomp a)
> 
> I used to think that the inferred type is the most general type, and
> that the compiler would accept as explicit the type that it itself
> inferred. I was wrong?
> 
> The second odd circumstance is best illustrated by the following
> transcript. Assume that /tmp/a.lhs is the text of the previous message
> as it was posted:
> 
>  $  ghci -fglasgow-exts /tmp/a.lhs
>  GHC Interactive, version 5.04.1, for Haskell 98.
>  Loading package base ... linking ... done.
>  Loading package haskell98 ... linking ... done.
>  Compiling Main             ( /tmp/a.lhs, interpreted )
> 
>  /tmp/a.lhs:76: Warning: No 'main' defined in module Main
>  Ok, modules loaded: Main.
>  *Main> let x = \f -> fapp f (('a','b'),('c',('d','e')))
>  Bus error (core dumped)
> 
> Incidentally, if I enter
> > x = \f -> fapp f (('a','b'),('c',('d','e')))
> into /tmp/a.lhs and load the file into GHCi, I get
> 
> ghc-5.04.1: panic! (the `impossible' happened, GHC version 5.04.1):
>         rdrNameModule zddFApp
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell