Opened 13 years ago

Closed 11 years ago

Last modified 4 years ago

#289 closed bug (fixed)

class context restrictions in GADT types not assumed

Reported by: ashley-y Owned by: simonpj
Priority: normal Milestone: 6.8.1
Component: Compiler (Type checker) Version: 6.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: gadt/data1, gadt/data2
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonpj)

I think this should compile:

	class C a where
		f :: a -> Bool

	data T a where
		MkT :: (C a) => a -> T a

	tf1 :: T Int -> Bool
	tf1 (MkT aa) = f aa

	tf2 :: T a -> Bool
	tf2 (MkT aa) = f aa

tf1 does not give an error, but tf2 does. The type signature for tf2 
should not need a class context, just as there's no "C Int" instance.

    No instance for (C a)
      arising from use of `f' at ThingEncoding.hs:32:23
    Probable fix: Add (C a) to the type signature(s) for `tf2'
    In the definition of `tf2': tf2 (MkT aa) = f aa

Change History (8)

comment:1 Changed 12 years ago by simonpj

Architecture: Unknown
Description: modified (diff)
difficulty: Unknown
Operating System: Unknown

Here is another example from Stephanie Weirich.

The reason I want this feature is that I want to conditionally include a context for an existentially quantified type variable. In other words, I want the following code to work:

class Foo a where

a -> Int

data T = forall a. T (G a)

data G a = A | Foo a => B a

doFoo :: T -> Int doFoo (T A) = 2 doFoo (T (B x)) = foo x

comment:2 Changed 11 years ago by simonpj

Milestone: 6.8

comment:3 Changed 11 years ago by simonpj

Resolution: Nonefixed
Status: assignedclosed

comment:4 Changed 11 years ago by simonpj

Test Case: gadt/data1, gadt/data2

Fixed by implication constraints.

comment:5 Changed 10 years ago by igloo

Milestone: 6.8 branch6.8.1

comment:6 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:7 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:8 Changed 4 years ago by simonpj <simonpj@…>

Note: See TracTickets for help on using tickets.