Opened 21 months ago

Closed 18 months ago

Last modified 18 months ago

#7102 closed bug (wontfix)

Type family instance overlap accepted in ghci

Reported by: exbb2 Owned by:
Priority: normal Milestone:
Component: GHCi Version: 7.4.1
Keywords: Cc: exbb2@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC accepts invalid program Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

This code works if I paste it line by line in ghci, but not if i try to load or compile it.

{-# LANGUAGE TypeFamilies #-}

data Rec a b =  Rec {unRec :: Rec a b -> b}

class RecursiveFun f where type A a b :: *; recurse :: f (A a b) b -> b

instance RecursiveFun Rec where type A a b = a; recurse r = unRec r r

instance RecursiveFun (->) where type A a b = Rec a b; recurse f = f (Rec f)

Change History (3)

comment:1 Changed 18 months ago by igloo

  • Difficulty set to Unknown
  • Resolution set to wontfix
  • Status changed from new to closed

I'm inclined to say that this is not a bug. In a similar way to how ghci lets you shadow variables:

Prelude> let f = 'a'
Prelude> let f = True
Prelude> f
True

it is letting you shadow type family instances:

Prelude> :set -XTypeFamilies
Prelude> type family F x :: *
Prelude> type instance F Int = Bool
Prelude> type instance F Int = Char
Prelude> :t undefined :: F Int
undefined :: F Int :: Char

I think that this makes sense: If you imagine that F is defined in some other package, and you are developing the type on the RHS, then if this were not possible then you'd have to restart ghci each time you alter the type.

comment:2 Changed 18 months ago by simonpj

It turns out that, as Ian says, this is by design. A new type instance declaration in GHCi replaces any earlier one with the same LHS.

But it was not documented, so I have added a note to the user manual to say so.

Simon

comment:3 Changed 18 months ago by simonpj@…

commit 232f1a2702684fe7f82a084213714adfa6162392

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Wed Oct 31 17:03:28 2012 +0000

    Add notes about type-family overlap in GHCi (see Trac #7102)

 docs/users_guide/ghci.xml         |    6 +++++-
 docs/users_guide/glasgow_exts.xml |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)
Note: See TracTickets for help on using tickets.