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