on d82d607 help sign in
49 lines 1.4 kB history raw
1{-# LANGUAGE Arrows #-}
2foo
3 f
4 g
5 h
6 ma = proc (
7 (a, b),
8 (c, d),
9 (e, f)
10 ) ->
11 do -- Begin do
12 (x,y) -- GHC parser fails if layed out over multiple lines
13 <- f -- Call into f
14 (a,
15 c) -- Tuple together arguments
16 (b,
17 d)
18 -< (b + 1, -- Funnel into arrow
19 d * b)
20 if
21 x `mod` y == 0 -- Basic condition
22 then case e -- Only left case is relevant
23 of Left (z,
24 w) -> \u -> -- Procs can have lambdas
25 let
26 v
27 = u -- Actually never used
28 ^ 2
29 in
30 (returnA
31 -< -- Just do the calculation
32 (x + y * z))
33 else do
34 let u = x -- Let bindings bind expressions, not commands
35 -- Could pattern match directly on x
36 i <- case u of
37 0 -> (g . h -< u)
38 n -> (
39 (h . g
40 -< y) -- First actual use of y
41 )
42 returnA -< ()
43 -- Sometimes execute effects
44 if i > 0
45 then ma -< ()
46 else returnA -< ()
47 returnA -< (i +
48 x *
49 y) -- Just do the calculation