Commit 1de8a034 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Add more GADT tests, this time concerning contexts in data constructors

parent dc689cd6
......@@ -25,6 +25,8 @@ clean(['Gadt17_help.hi', 'Gadt17_help.o'])
test('gadt18', normal, compile, [''])
test('gadt19', normal, compile, [''])
test('gadt20', normal, compile, [''])
test('gadt21', normal, compile_fail, [''])
test('gadt22', normal, compile, [''])
test('red-black', normal, compile, [''])
test('type-rep', skip_if_fast, compile_and_run, [''])
......
{-# OPTIONS -fglasgow-exts #-}
-- Fails (needs the (Ord a) in TypeSet
-- c.f. gadt22.hs
module Expr where
import Data.Set (Set)
data Type a where
TypeInt :: Type Int
TypeSet :: {- Ord a => -} Type a -> Type (Set a)
TypeFun :: Type a -> Type b -> Type (a -> b)
data Expr :: * -> * where
Const :: Type a -> a -> Expr a
data DynExpr = forall a. DynExpr (Expr a)
withOrdDynExpr :: DynExpr -> (forall a. Ord a => Expr a -> b) -> Maybe b
withOrdDynExpr (DynExpr e@(Const (TypeSet _) _)) f = Just (f e)
withOrdDynExpr (DynExpr e@(Const TypeInt _)) f = Just (f e)
withOrdDynExpr _ _ = Nothing
gadt21.hs:21:59:
Could not deduce (Ord a2) from the context ()
arising from a use of `f' at gadt21.hs:21:59-61
Possible fix:
add (Ord a2) to the context of the constructor `TypeSet'
In the first argument of `Just', namely `(f e)'
In the expression: Just (f e)
In the definition of `withOrdDynExpr':
withOrdDynExpr (DynExpr (e@(Const (TypeSet _) _))) f = Just (f e)
{-# OPTIONS -fglasgow-exts #-}
-- Succeeds (needs the (Ord a) in TypeSet
-- c.f. gadt21.hs
-- However, it's a useful test because it unearthed a bug
-- in free-variable-finding
module Expr where
import Data.Set (Set)
data Type a where
TypeInt :: Type Int
TypeSet :: Ord a => Type a -> Type (Set a)
TypeFun :: Type a -> Type b -> Type (a -> b)
data Expr :: * -> * where
Const :: Type a -> a -> Expr a
data DynExpr = forall a. DynExpr (Expr a)
withOrdDynExpr :: DynExpr -> (forall a. Ord a => Expr a -> b) -> Maybe b
withOrdDynExpr (DynExpr e@(Const (TypeSet _) _)) f = Just (f e)
withOrdDynExpr (DynExpr e@(Const TypeInt _)) f = Just (f e)
withOrdDynExpr _ _ = Nothing
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment