X-Git-Url: http://git.megacz.com/?p=coq-hetmet.git;a=blobdiff_plain;f=examples%2FCommandSyntaxExample.hs;fp=examples%2FCommandSyntaxExample.hs;h=e06920c174cff3a9cdf7bca1f4b149ef4d23584f;hp=0000000000000000000000000000000000000000;hb=caa7ad74b99b34abc5181553e66423da6bdfee26;hpb=e3e2ce9cb83acdd8191049b4e9bd3d4fcf6a4db4 diff --git a/examples/CommandSyntaxExample.hs b/examples/CommandSyntaxExample.hs new file mode 100644 index 0000000..e06920c --- /dev/null +++ b/examples/CommandSyntaxExample.hs @@ -0,0 +1,40 @@ +{-# OPTIONS_GHC -XModalTypes -XMultiParamTypeClasses -ddump-types -XNoMonoPatBinds #-} +module CommandSyntaxExample +where + +-- +-- Please ignore this; I never got around to implementing it. +-- + +{- +The example may seem a little contrived, but its purpose is to +illustrate the be- haviour when the argument of mapC refers both to +its parameter and a free vari- able (n). + +\begin{verbatim} +-- we can use mapA rather than mapC (from page 100) + +mapA f = proc xs -> case xs of +[] -> returnA -< [] x:xs’ -> do y <- f -< x +ys’ <- mapA f -< xs’ returnA -< y:ys + +example2 = + <[ \(n,xs) -> + ~(mapA <[ \x-> (~(delay 0) n, x) ]> ) + xs + ]> + +<[ example2 (n,xs) = + ~(mapA <[ \x-> (~(delay 0) n, x) ]> ) xs ]> +\end{verbatim} + + +-- from Hughes' "programming with Arrows" + +mapC :: ArrowChoice arr => arr (env,a) b -> arr (env,[a]) [b] mapC c = proc (env,xs) -> +case xs of [] -> returnA -< [] x:xs’ -> do y <- c -< (env,x) +ys <- mapC c -< (env,xs’) returnA -< y:ys + +example2 = proc (n,xs) -> (| mapC (\x-> do delay 0 -< n +&&& do returnA -< x) |) xs +-}