Ticket #1204 (closed bug: fixed)
Associated types don't work with record updates
| Reported by: | nominolo@… | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.8.1 |
| Component: | Compiler (Type checker) | Version: | 6.7 |
| Keywords: | Cc: | ||
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | Difficulty: | Unknown | |
| Test Case: | Records.hs | Blocked By: | |
| Blocking: | Related Tickets: |
Description
(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'
Change History
Note: See
TracTickets for help on using
tickets.
