[GHC] #1204: Associated types don't work with record updates
GHC
trac at galois.com
Tue Mar 6 18:18:48 EST 2007
#1204: Associated types don't work with record updates
-----------------------------------+----------------------------------------
Reporter: nominolo at gmail.com | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.7
Severity: normal | Keywords:
Difficulty: Unknown | Testcase:
Architecture: Unknown | Os: Unknown
-----------------------------------+----------------------------------------
(I couldn't find a more descriptive title, feel free to change it)
When instantiating associated types with records, record update doesn't
seem to work (at least in indirect uses). I think it should. If this is
supposed to fail, then a more helpful error message might be very useful.
Here's the code:
{{{
{-# OPTIONS -findexed-types #-}
module Bug where
------------------------------------------------------------------------------
class C c where
data D1 c
class C c => D c where
works :: Int -> D1 c -> D1 c
buggy :: Int -> D1 c -> D1 c
buggy2 :: Int -> D1 c -> D1 c
------------------------------------------------------------------------------
data FooC = FooC
instance C FooC where
data D1 FooC = D1F { moo :: Int }
instance D FooC where
works x d = d -- d unchanged, so OK
buggy x d@(D1F { moo = k }) =
d { moo = k + x } -- d is updated wrong type--why?
buggy2 x d@(D1F { moo = k }) =
(d :: D1 FooC) { moo = k + x } -- type annotation doesn't work
}}}
GHC Output:
{{{
$ ghc67 -v -c Bug67.hs
Glasgow Haskell Compiler, Version 6.7.20070303, for Haskell 98, compiled
by GHC version 6.7.20070303
Using package config file: /usr/local/lib/ghc-6.7.20070303/package.conf
wired-in package base mapped to base-2.0
wired-in package rts mapped to rts-1.0
wired-in package haskell98 mapped to haskell98-1.0
wired-in package template-haskell mapped to template-haskell-2.0
Hsc static flags: -static
Created temporary directory: /tmp/ghc422_0
*** Checking old interface for main:Bug:
*** Parser:
*** Renamer/typechecker:
Bug67.hs:25:4:
Couldn't match expected type `D1 FooC'
against inferred type `(Bug.:R2D1)'
In the expression: d {moo = k + x}
In the definition of `buggy':
buggy x (d@(D1F {moo = k})) = d {moo = k + x}
In the definition for method `buggy'
Bug67.hs:28:4:
Couldn't match expected type `D1 FooC'
against inferred type `(Bug.:R2D1)'
In the expression: (d :: D1 FooC) {moo = k + x}
In the definition of `buggy2':
buggy2 x (d@(D1F {moo = k})) = (d :: D1 FooC) {moo = k + x}
In the definition for method `buggy2'
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1204>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list