blob: b9cbf8fa1addb72836b65cee27a4664d09766b31 (
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
28
29
30
31
32
33
34
35
|
-- From comment:76 in #9858
-- This exploit still works in GHC 7.10.1.
-- By Shachaf Ben-Kiki, Ørjan Johansen and Nathan van Doorn
{-# LANGUAGE Safe #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ImpredicativeTypes #-}
module T9858a where
import Data.Typeable
type E = (:~:)
type PX = Proxy (((),()) => ())
type PY = Proxy (() -> () -> ())
data family F p a b
newtype instance F a b PX = ID (a -> a)
newtype instance F a b PY = UC (a -> b)
{-# NOINLINE ecast #-}
ecast :: E p q -> f p -> f q
ecast Refl = id
supercast :: F a b PX -> F a b PY
supercast = case cast e of
Just e' -> ecast e'
where
e = Refl
e :: E PX PX
uc :: a -> b
uc = case supercast (ID id) of UC f -> f
|