Mysterious type error with Glasgow Haskell
Simon Peyton-Jones
simonpj at microsoft.com
Mon Oct 22 09:30:49 EDT 2001
George
For a change, this is your fault! You wrote:
let
minus :: Int -> Int -> Int
minus = (-)
toRValue :: Int -> Radio value
toRValue -1 = NoRadio -- (*)
toRValue i = ...
Alas, the line marked (*) defines the infix operator (-). So
in effect you have
let
(-) toRValue 1 = NoRadio
minus = (-)
toRValue i = ...
And then the result you get isn't surprising. Solution: put
parens round your (-1).
I don't see how to give a better error message given the
defn of Haskell as it is! But it's a nice example.
Simon
| -----Original Message-----
| From: George Russell [mailto:ger at tzi.de]
| Sent: 18 October 2001 15:55
| To: glasgow-haskell-bugs at haskell.org; Simon Peyton-Jones; Simon Marlow
| Subject: Mysterious type error with Glasgow Haskell
|
|
| Hello Glasgow hackers (cc'd to both Simons as the mailing
| list will complain that this bug report is too big).
|
| If you don't redefine the (-) operator, then
|
| minus :: Int -> Int -> Int
| minus = (-)
| should work, shouldn't it? Also it should be equivalent to
| minus :: Int -> Int -> Int
| minus a b = a + (-1) * b
|
| The attached bzip2 file contains (1) a lot of .hi files; (2)
| a file SimpleForm.hs. Compiling it with ghc5.02 on
| Sparc/Solaris, with the following command line:
|
| /usr/local/pub-bkb/ghc/ghc-latest/bin/ghc -c
| toolkit/SimpleForm.hs -package concurrent -package data
| -package net -package posix -package text -package util
| -package lang
| -i.:packer:resources:canvasitems:kernel:containers:menuitems:t
| oolkit:components:toplevel:widgets:devices:textitems:tix:/home
| /ger/uni/util:/home/ger/uni/events:/home/ger/uni/reactor:/home
| /ger/uni/server:/home/ger/uni/htk:/home/ger/uni/davinci:/home/
| ger/uni/graphs:/home/ger/uni/tools:/home/ger/uni/cvs:/home/ger
| /uni/types -fglasgow-exts -fallow-overlapping-instances
| -fallow-undecidable-instances -cpp -ddump-hi-diffs -H25M
| -recomp -fwarn-deprecations -Onot -DDEBUG -Onot -H30M -fasm
|
| gives an error:
|
| toolkit/SimpleForm.hs:379:
| Couldn't match `Int' against `Radio x'
| Expected type: Int -> Int -> Int
| Inferred type: Int -> Int -> Radio x
| In the definition of `minus': (-)
|
| However if you go to line 379, comment out the line "minus =
| (-)" and decomment the next line to give "minus a b = a +
| (-1) * b" the error message magically disappears and it goes
| through the compiler.
|
| Am I somehow mistaken, or is this a bug in GHC?
|
More information about the Glasgow-haskell-bugs
mailing list