1 {-# OPTIONS_GHC -XModalTypes -XMultiParamTypeClasses -ddump-types -XNoMonoPatBinds #-}
2 module CommandSyntaxExample
6 -- Please ignore this; I never got around to implementing it.
10 The example may seem a little contrived, but its purpose is to
11 illustrate the be- haviour when the argument of mapC refers both to
12 its parameter and a free vari- able (n).
15 -- we can use mapA rather than mapC (from page 100)
17 mapA f = proc xs -> case xs of
18 [] -> returnA -< [] x:xs’ -> do y <- f -< x
19 ys’ <- mapA f -< xs’ returnA -< y:ys
23 ~(mapA <[ \x-> (~(delay 0) n, x) ]> )
28 ~(mapA <[ \x-> (~(delay 0) n, x) ]> ) xs ]>
32 -- from Hughes' "programming with Arrows"
34 mapC :: ArrowChoice arr => arr (env,a) b -> arr (env,[a]) [b] mapC c = proc (env,xs) ->
35 case xs of [] -> returnA -< [] x:xs’ -> do y <- c -< (env,x)
36 ys <- mapC c -< (env,xs’) returnA -< y:ys
38 example2 = proc (n,xs) -> (| mapC (\x-> do delay 0 -< n
39 &&& do returnA -< x) |) xs