forked from leepike/Copilot
/
Local.hs
43 lines (32 loc) · 1.08 KB
/
Local.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--------------------------------------------------------------------------------
-- Copyright © 2011 National Institute of Aerospace / Galois, Inc.
--------------------------------------------------------------------------------
-- | Example demonstrating local variables.
module Local ( localEx ) where
import Prelude ()
import Language.Copilot
--------------------------------------------------------------------------------
nats :: Stream Int32
nats = [0] ++ (1 + nats)
strm :: Stream Int32
strm =
local (nats + 1) $ \nats' -> nats' + nats'
-- The above code corresponds to
--
-- strm :: Stream Int32
-- strm =
-- let x = nats * nats
-- in x + x
spec :: Spec
spec = do
trigger "strm" true [arg strm]
-- trigger "strm" true [arg $ replStrm 100000]
-- trigger "strm" true [arg $ replStrm_ 100000 10000]
-- observer "nats" nats
-- observer "strm" strm
--------------------------------------------------------------------------------
localEx :: IO ()
localEx = do
interpret 20 spec
prettyPrint spec
--------------------------------------------------------------------------------