note to self in HaskWeak
[coq-hetmet.git] / examples / CommandSyntaxExample.hs
1 {-# OPTIONS_GHC -XModalTypes -XMultiParamTypeClasses -ddump-types -XNoMonoPatBinds  #-}
2 module CommandSyntaxExample
3 where
4
5 --
6 -- Please ignore this; I never got around to implementing it.
7 --
8
9 {-
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).
13
14 \begin{verbatim}
15 -- we can use mapA rather than mapC (from page 100)
16
17 mapA f = proc xs -> case xs of
18 [] -> returnA -< [] x:xs’ -> do y <- f -< x
19 ys’ <- mapA f -< xs’ returnA -< y:ys
20
21 example2 =
22    <[ \(n,xs) -> 
23        ~(mapA <[ \x-> (~(delay 0) n, x) ]> )
24         xs
25     ]>
26
27 <[ example2 (n,xs) =
28    ~(mapA <[ \x-> (~(delay 0) n, x) ]> ) xs ]>
29 \end{verbatim}
30
31
32 -- from Hughes' "programming with Arrows"
33
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
37
38 example2 = proc (n,xs) -> (| mapC (\x-> do delay 0 -< n
39 &&& do returnA -< x) |) xs
40 -}