-
Notifications
You must be signed in to change notification settings - Fork 37
/
T433.hs
72 lines (57 loc) · 1.46 KB
/
T433.hs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module T433 where
import Data.Kind (Type)
import Data.Singletons.Base.TH
import Prelude.Singletons
$(promote [d|
konst1 :: a -> Bool -> a
konst1 x _ = x
konst2 :: a -> Maybe Bool -> a
konst2 x _ = x
f local = g
where
g :: forall a. a -> a
g x = konst1 (x :: a) local
foo :: forall a. a -> ()
foo x = const () (Nothing :: Maybe a)
id2 :: forall a. a -> a
id2 x = id (x :: a)
id3 :: a -> a
id3 (x :: b) = id (x :: b)
id4 :: forall a. a -> a
id4 (x :: a) = id (x :: a)
id5 :: forall a. a -> a
id5 = g
where
g = id :: a -> a
id6 :: a -> a
id6 (x :: b) = g
where
g = (x :: b)
id7 (x :: b) = g
where
g = (x :: b)
id8 :: a -> a
id8 x = g x True
where
g :: b -> a -> b
g y _ = y
-- These version will not work. See the singletons README for more about these
-- limitations.
-- This will not work because the `a` in `forall a` scopes over the body of
-- the function, but the `(x :: b)` pattern refers to `b` instead of `a`.
{-
id9 :: forall a. a -> a
id9 (x :: b) = id (x :: b)
-}
-- This will not work because the `b` in `Nothing :: Maybe b` is bound by the
-- type signature for `g`, a local variable that closes over `x`. Moreover,
-- `b` is only mentioned in the return type (and not the arguments) of the
-- type signature.
{-
id10 :: forall a. a -> a
id10 x = konst2 x y
where
y :: forall b. Maybe b
y = Nothing :: Maybe b
-}
|])