Opened 9 years ago

Closed 7 years ago

Last modified 3 months 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: Difficulty: Unknown
Test Case: gadt/data1, gadt/data2 Blocked By:
Blocking: Related Tickets:

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.

ThingEncoding.hs:32:23:
    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 8 years ago by simonpj

  • Architecture set to Unknown
  • Description modified (diff)
  • Difficulty set to Unknown
  • Operating System set to 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

foo
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 8 years ago by simonpj

  • Milestone set to 6.8

comment:3 Changed 7 years ago by simonpj

  • Resolution changed from None to fixed
  • Status changed from assigned to closed

comment:4 Changed 7 years ago by simonpj

  • Test Case set to gadt/data1, gadt/data2

Fixed by implication constraints.

comment:5 Changed 6 years ago by igloo

  • Milestone changed from 6.8 branch to 6.8.1

comment:6 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:7 Changed 6 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:8 Changed 3 months ago by simonpj <simonpj@…>

Note: See TracTickets for help on using tickets.