blob: 8db7a485a387f997a83ec813ae9e77604d4e08ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
{-# LANGUAGE TypeFamilies, GADTs, ConstraintKinds, RankNTypes #-}
module T5655 where
import Data.Kind (Constraint)
class Show a => Twice a where twice :: a -> a
instance Twice Int where twice = (*2)
data ETwice where ETwice :: Twice a => a -> ETwice
class E e where
type C e :: * -> Constraint
ap :: (forall a. C e a => a -> r) -> e -> r
instance E ETwice where
type C ETwice = Twice
ap f (ETwice a) = f a
f :: (E e, C e ~ Twice) => e -> ETwice
f = ap (ETwice . twice)
foo :: ETwice
foo = ETwice (5 :: Int)
bar :: IO ()
bar = ap print (f foo)
|