-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes2oct.hs
146 lines (73 loc) · 1.97 KB
/
notes2oct.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import Control.Monad
import Control.Applicative
data M2 t a = M2 (t (Either a a), t (Either a a))
instance (Functor t) => Functor (M2 t) where
fmap :: (a -> b) -> (M2 t a -> M2 t b)
fmap = undefined
instance (Monad t) => Applicative (M2 t) where
pure :: a -> M2 t a
pure = undefined
(<*>) = ap
instance (Monad t) => Monad (M2 t) where
(>>=) :: M2 t a -> (a -> M2 t b) -> M2 t b
(>>=) = undefined
{-- verify properties
return x >>= f == f x
x >>= return == x
(f# . g)# == f# . g#
x >>= (\y -> g y >>= f) == (x >>= g) >>= f
--}
{--
data Maybe a = Nothing | Just a
Just [1,2,3] :: Maybe [Int]
M2 Maybe a = (Maybe (Either a a) , Maybe (Either a a))
m :: Maybe (Either a a)
m = Nothing
ou
m = Just y where y :: Either a a
m = Nothing
ou
m = Just (Left x) where x :: a
ou
m = Just (Right x) where x :: a
--}
{--
(a -> M2 t b) -> (M2 t a -> M2 t b)
functor:
(a -> b) -> (F a -> F b)
extension:
(a -> M b) -> (M a -> M b)
(=<<) :: (a -> M b) -> M a -> M b
(=<<) = flip (>>=)
f:: a -> M b
fmap f :: M a -> M (M b)
[M f]
join :: M (M b) -> M b
[mu]
join . fmap f :: M a -> Mb
--}
data Coprod3 a b c = Left3 a | Middle3 b | Right3 c
Prod x = [x]
split :: (a -> b1) -> (a -> b2) -> (a -> (b1,b2))
split f g x = (f x, g x)
split :: (a -> b1, a -> b2) -> (a -> (b1,b2))
split (f,g) x = (f x, g x)
split :: (a -> b, a -> b) -> (a -> (b,b))
split (f,g) x = (f x, g x)
split :: Prod (a -> b) -> (a -> Prod b)
split :: [a -> b] -> (a -> [b])
type Twice x = Either x x
Coprod x = (Int, x)
(2,'a') :: Coprod Char
Left 'a' (0,'a')
Right 'a' (1,'a')
Left3 'a' (0,'a')
Middle3 'a' (1,'a')
Right3 'a' (2,'a')
either :: (a1 -> b) -> (a2 -> b) -> (Either a1 a2 -> b)
either f g (Left x) = f x
either f g (Right x) = g x
either' :: (a1 -> b, a2 -> b) -> (Either a1 a2 -> b)
either' (f, g) (Left x) = f x
either' (f, g) (Right x) = g x
coprod :: Prod (a -> b) -> (Coprod a -> b)