Basically a reprint from https://vimeo.com/152110601

The motivation is to pass some info down the stack, but without the tedious syntax of extra arguments. The gist, as I understand, is to capture the extra argument in a function, treated as a single argument (function as first-class citizen), and pass that down the stack.

Still, the function-as-monad thing isn’t very intuitive; container metaphor serves me pretty mostly.

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
import Prelude hiding ((>>=), return)

-- f :: Int -> Int
-- f x =
-- let r = g x
-- in r

-- g :: Int -> Int
-- g x =
-- let r = h x
-- in r

-- h :: Int -> Int
-- h x = x


-- f :: Int -> Bool -> Int
-- f x y =
-- let r = g x y
-- in r

-- g :: Int -> Bool -> Int
-- g x y =
-- let r = h x y
-- in r

-- h :: Int -> Bool -> Int
-- h x y = if y then x else x

-- type MyBool a = Bool -> a

-- f :: Int -> MyBool Int
-- f x y =
-- let r = g x y
-- in r

-- g :: Int -> MyBool Int
-- g x y =
-- let r = h x y
-- in r

-- h :: Int -> MyBool Int
-- h x y = if y then x else x

type MyBool a = Bool -> a

(>>=) :: MyBool a -> (a -> MyBool b) -> MyBool b
l >>= f = \x -> f (l x) x

return :: a -> MyBool a
return x _ = x

f :: Int -> MyBool Int
f x =
(g x) >>=
(\r -> return r)

g :: Int -> MyBool Int
g x =
(h x) >>=
(\r -> return r)

h :: Int -> MyBool Int
-- h x y = if y then x else x
h x = ask >>= (\y -> return $ if y then x else x)

ask :: MyBool Bool
ask = id

main = undefined