Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changes to examples.

  • Loading branch information...
commit cba5c9d6dc2e3787fbbcae3548678b95460affc6 1 parent 4ea893d
@leepike authored
View
37 Examples/Local.hs
@@ -9,6 +9,7 @@ module Main where
import qualified Prelude as P
import Copilot.Language
import Copilot.Language.Prelude
+import Data.List (replicate, foldl')
--------------------------------------------------------------------------------
@@ -17,8 +18,21 @@ nats = [0] ++ (1 + nats)
strm :: Stream Int32
strm =
- local "x" (nats * nats) $
- var "x" + var "x"
+ local (nats + 1) $ \nats' -> nats' + nats'
+
+replStrm :: Int -> Stream Int32
+replStrm i =
+ local (nats + 1) $ \nats' -> plus nats'
+ where
+ plus :: Stream Int32 -> Stream Int32
+ plus nats' = foldl' (+) 0 (replicate i nats')
+
+replStrm_ :: Int -> Int -> Stream Int32
+replStrm_ i j =
+ local (replStrm i) $ \sum -> plus sum
+ where
+ plus :: Stream Int32 -> Stream Int32
+ plus sum = foldl' (+) 0 (replicate j sum)
-- The above code corresponds to
--
@@ -28,17 +42,18 @@ strm =
-- in x + x
spec :: Spec
-spec =
- do
- observer "nats" nats
- observer "strm" strm
+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
--------------------------------------------------------------------------------
main :: IO ()
-main =
- do
- interpret 20 [] spec
- prettyPrint spec
+main = do
+ interpret 20 [] spec
+ prettyPrint spec
---------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
View
13 Examples/Random.hs
@@ -1,14 +1,13 @@
import Copilot.Core.PrettyPrint as P
-import Copilot.Core.Random (random)
-import Copilot.Core.Random.Weights
+import Copilot.Core.Random (randomSpec)
+import Copilot.Core.Random.Weights (simpleWeights)
import Copilot.Language
import Copilot.Language.Prelude
import qualified Prelude as P
import System.Random (newStdGen)
main :: IO ()
-main =
- do
- g <- newStdGen
- let p = random simpleWeights g
- putStrLn (P.prettyPrint p)
+main = do
+ g <- newStdGen
+ let p = randomSpec simpleWeights g
+ putStrLn (P.prettyPrint p)
View
10 Examples/RegExpExamples.hs
@@ -49,10 +49,8 @@ test2 = copilotRegexpB
spec = do
- observer "test1" test1
- observer "test2" test2
- observer "reset" reset
+ observer "test1" test1
+ observer "test2" test2
+ observer "reset" reset
-
-test = do
- interpret 15 [ input "e" e ] spec
+test = interpret 15 [ input "e" e ] spec
View
17 Examples/VotingExamples.hs
@@ -25,7 +25,7 @@ vote = do
maj = majority xs
xs = concat (replicate 1 ls)
- ls = [a, b, c, d, e, f, g, h, i, j, k]
+ ls = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
a = [0] ++ a + 1 :: Stream Word32
b = [0] ++ b + 1
@@ -38,6 +38,21 @@ vote = do
i = [1] ++ i + 1
j = [1] ++ j + 1
k = [1] ++ k + 1
+ l = [1] ++ l + 1
+ m = [1] ++ m + 1
+ n = [1] ++ n + 1
+ o = [1] ++ o + 1
+ p = [1] ++ p + 1
+ q = [1] ++ q + 1
+ r = [1] ++ r + 1
+ s = [1] ++ s + 1
+ t = [1] ++ t + 1
+ u = [1] ++ u + 1
+ v = [1] ++ v + 1
+ w = [1] ++ w + 1
+ x = [1] ++ x + 1
+ y = [1] ++ y + 1
+ z = [1] ++ z + 1
--------------------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.