[GHC] #8155: Defaulting bug or unfortunate error message with closed type families
GHC
ghc-devs at haskell.org
Thu Aug 22 08:46:04 UTC 2013
#8155: Defaulting bug or unfortunate error message with closed type families
------------------------------------+-------------------------------------
Reporter: nh2 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
------------------------------------+-------------------------------------
https://github.com/nh2/infinite-type-families/blob/master/Test2.hs
Some code extracted from hmatrix:
{{{
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
module Test where
data Vector a = Vector a
data Matrix a = Matrix a
class Build f where
build' :: BoundsOf f -> f -> ContainerOf f
#if __GLASGOW_HASKELL__ <= 706
-- Normal type families with GHC 7.6, works well.
type family BoundsOf x
type instance BoundsOf (a->a) = Int
type instance BoundsOf (a->a->a) = (Int,Int)
type family ContainerOf x
type instance ContainerOf (a->a) = Vector a
type instance ContainerOf (a->a->a) = Matrix a
#else
-- Closed type families for GHC 7.8
type family BoundsOf x where
BoundsOf (a->a->a) = (Int,Int)
BoundsOf (a->a) = Int
type family ContainerOf x where
ContainerOf (a->a) = Vector a
ContainerOf (a->a->a) = Matrix a
#endif
instance (Num a) => Build (a->a) where
build' = buildV
buildV :: (Integral a, Num b) => a -> (b -> c) -> Vector c
buildV _ _ = undefined
}}}
This is probably related to #8154.
With GHC 7.7, we get the following error:
{{{
Test2.hs:59:14:
Could not deduce (BoundsOf (a -> a) ~ Integer)
from the context (Num a)
bound by the instance declaration at Test2.hs:58:10-32
Expected type: BoundsOf (a -> a)
-> (a -> a) -> ContainerOf (a -> a)
Actual type: Integer -> (a -> a) -> Vector a
Relevant bindings include
build' :: BoundsOf (a -> a) -> (a -> a) -> ContainerOf (a -> a)
(bound at Test2.hs:59:5)
In the expression: buildV
In an equation for ‛build'’: build' = buildV
}}}
1) Where does this Integer come from?
2) Change
{{{
BoundsOf (a->a) = Int
}}}
into
{{{
BoundsOf (a->a) = Integer
}}}
You get the same error message, although clearly {{{BoundsOf (a -> a) ~
Integer}}}
(you just wrote that down).[[BR]]
Even if the order matters in closed type families, is this not the
wrong error message?
3) If you flip the order so that the (a->a) case comes first, it works
(with both it Int or Integer). I don't quite understand why.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8155>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list