Skip to content

Instantly share code, notes, and snippets.

@YoEight
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YoEight/c154d983f6443d8971d5 to your computer and use it in GitHub Desktop.
Save YoEight/c154d983f6443d8971d5 to your computer and use it in GitHub Desktop.
Is that a bug ? (GHC 7.8.2)
{-# LANGUAGE GADTs, ExistentialQuantification, RankNTypes #-}
data A
data B
data C
data Foo a where
FooA :: Foo A
FooB :: Foo B
FooC :: Foo C
data Baz = forall a. Baz (Foo a)
unBaz :: (forall a. Foo a -> r) -> Baz -> r
unBaz k (Baz x) = k x
test :: Baz -> Char -- compile error
test = unBaz go where
go FooA = 'a'
go FooB = 'b'
go FooC = 'c'
[1 of 1] Compiling Main ( bug.hs, interpreted )
bug.hs:19:13:
Couldn't match expected type ‘t’ with actual type ‘Char’
‘t’ is untouchable
inside the constraints (t1 ~ A)
bound by a pattern with constructor
FooA :: Foo A,
in an equation for ‘go’
at bug.hs:19:6-9
‘t’ is a rigid type variable bound by
the inferred type of go :: Foo t1 -> t at bug.hs:19:3
Relevant bindings include go :: Foo t1 -> t (bound at bug.hs:19:3)
In the expression: 'a'
In an equation for ‘go’: go FooA = 'a'
In an equation for ‘test’:
test
= unBaz go
where
go FooA = 'a'
go FooB = 'b'
go FooC = 'c'
bug.hs:20:13:
Couldn't match expected type ‘t’ with actual type ‘Char’
‘t’ is untouchable
inside the constraints (t1 ~ B)
bound by a pattern with constructor
FooB :: Foo B,
in an equation for ‘go’
at bug.hs:20:6-9
‘t’ is a rigid type variable bound by
the inferred type of go :: Foo t1 -> t at bug.hs:19:3
Relevant bindings include go :: Foo t1 -> t (bound at bug.hs:19:3)
In the expression: 'b'
In an equation for ‘go’: go FooB = 'b'
In an equation for ‘test’:
test
= unBaz go
where
go FooA = 'a'
go FooB = 'b'
go FooC = 'c'
bug.hs:21:13:
Couldn't match expected type ‘t’ with actual type ‘Char’
‘t’ is untouchable
inside the constraints (t1 ~ C)
bound by a pattern with constructor
FooC :: Foo C,
in an equation for ‘go’
at bug.hs:21:6-9
‘t’ is a rigid type variable bound by
the inferred type of go :: Foo t1 -> t at bug.hs:19:3
Relevant bindings include go :: Foo t1 -> t (bound at bug.hs:19:3)
In the expression: 'c'
In an equation for ‘go’: go FooC = 'c'
In an equation for ‘test’:
test
= unBaz go
where
go FooA = 'a'
go FooB = 'b'
go FooC = 'c'
@YoEight
Copy link
Author

YoEight commented Jul 19, 2014

Fixed by annoting go like this: go :: Foo a -> Char. Thanks @lucasdicioccio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment