GHC 6.10.1 type puzzler
bayer at cpw.math.columbia.edu
Wed Nov 19 11:40:39 EST 2008
Here is an example illustrating a type problem I've having with GHC
> module Main where
> newtype Box a = B a
> make :: a -> Box a
> make x = B x
> val :: Box a -> a
> val (B x) = x
> test1 :: Box a -> a -> [a]
> test1 box x = go box x
> go :: Box a -> a -> [a]
> go b y = [(val b), y]
> test2 :: Box a -> a -> [a]
> test2 box x = go x
> -- go :: a -> [a]
> go y = [(val box), y]
> main :: IO ()
> main = do
> print $ test1 (make 1) 2
If I uncomment the commented type declaration, I get the familiar error
> Couldn't match expected type `a1' against inferred type `a'
On the other hand, the earlier code is identical except that it passes
an extra argument, and GHC matches the types without complaint.
This is a toy example to isolate the issue; in the actual code one
wants a machine-checkable type declaration to help understand the
function, which is local to save passing an argument. To the best of
my understanding, I've given the correct type, but GHC won't make the
inference to unify the type variables.
I wonder if I found a GHC blind spot. However, it is far more likely
that my understanding is faulty here. Any thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Glasgow-haskell-users