8 list :: [Int] -> *v *[Int]
9 (++.) infixr 5 :: *(v *[Int]) *(v *[Int]) -> *(v *[Int])
13 (!.) infixl 9 :: *(v *[Int]) *(v Int) -> *(v Int)
17 lit :: a -> *(v a) | toStringU a
18 (+.) infixl 6 :: *(v Int) *(v Int) -> *(v Int)
19 (-.) infixl 6 :: *(v Int) *(v Int) -> *(v Int)
20 (*.) infixl 7 :: *(v Int) *(v Int) -> *(v Int)
21 (/.) infixl 7 :: *(v Int) *(v Int) -> *(v Int)
22 If :: *(v Bool) *(v a) *(v a) -> *(v a)
26 (>>*.) infixl 1 :: *(v .t) *[Step *v .t .u] -> *(v .u)
29 = IfValue ((v t) -> *(v Bool, v t)) ((v t) -> v u)
34 toStringU :: .a -> String
36 instance toStringU Bool
38 toStringU :: !.Bool -> String
45 instance toStringU Int
47 toStringU :: !.Int -> String
55 instance toStringU String
57 toStringU :: !.String -> String
63 show :: u:a -> *(State String u:b) | toStringU a
64 show x = State \s -> (undef, s +++ toStringU x)
66 instance list (State String)
68 list x = show " list " >>| pure undef
69 (++.) l r = l >>| show " ++ " >>| r >>| pure undef
71 instance select (State String)
73 // >>| expects both sides to have the same attribute, this is not the case
75 (!.) a i = a >>| show " ! " >>| i >>| pure undef
77 instance expr (State String)
80 (+.) l r = l >>| show " + " >>| r >>| pure undef
81 (-.) l r = l >>| show " - " >>| r >>| pure undef
82 (*.) l r = l >>| show " * " >>| r >>| pure undef
83 (/.) l r = l >>| show " / " >>| r >>| pure undef
84 If b t e = show "If " >>| b >>| t >>| e >>| pure undef
86 instance step (State String)
88 (>>*.) l cs = l >>| show " >>*. [" >>|
91 printSteps [] = show "]"
92 printSteps [IfValue p c:cs]
93 # (pb, pr) = p (show "i")
94 = show "IfValue (\\i->(" >>| pb >>| show ", " >>| pr >>| show ")) (\\v->" >>| c (show "v") >>| show ")" >>| commaCont cs
95 printSteps [Always c:cs] = show "Always " >>| c >>| commaCont cs
97 commaCont [] = printSteps []
98 commaCont cs = show ", " >>| printSteps cs
102 list x = undef//Just x
103 (++.) l r = l >>= \l -> r >>= \r -> pure (l ++ r)
105 instance select Maybe
107 (!.) a i = a >>= \a -> i >>= \i -> pure (a!!i)
112 (+.) l r = l >>= \l -> r >>= \r -> pure (l + r)
113 (-.) l r = l >>= \l -> r >>= \r -> pure (l - r)
114 (*.) l r = l >>= \l -> r >>= \r -> pure (l * r)
115 (/.) _ (Just 0) = Nothing
116 (/.) l r = l >>= \l -> r >>= \r -> pure (l / r)
123 (>>*.) _ [] = Nothing
124 (>>*.) _ [Always c:_] = c
125 (>>*.) Nothing [_:cs] = Nothing >>*. cs
126 (>>*.) v=:(Just _) [IfValue p c:cs]
128 (Nothing, v) = Nothing
129 (Just b, v) = if b (c v) (v >>*. cs)
131 Start :: (Maybe Int, String, Maybe Int, String)
132 Start = (lit 1 +. lit 2, snd (runState (lit 1 +. lit 2) ""), t, snd (runState t ""))
134 t :: *(v Int) | expr, step v
135 t = lit 38 /. lit 0 >>*.
136 [ IfValue (\v->(lit True, v)) (\i->i)