summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/T5655.hs
blob: 5da477a466a09b23f23db2eba61dcaaf7a5ce85a (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 (Type, 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 :: Type -> 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)