Skip to content

Commit 9a19787

Browse files
committed
Use version 0.2.3, fix examples, add recursion example
1 parent 142a99b commit 9a19787

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

Main.hs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ data Response = Response (Either String Compiled)
4444
compile :: String -> IO Response
4545
compile input | length input > 5000 = return $ Response $ Left "Please limit your input to 5000 characters"
4646
compile input = do
47-
case P.runIndentParser P.parseDeclarations input of
47+
case P.runIndentParser P.parseModules input of
4848
Left parseError -> do
4949
return $ Response $ Left $ show parseError
50-
Right decls -> do
51-
case P.compile decls of
50+
Right modules -> do
51+
case P.compile modules of
5252
Left error ->
5353
return $ Response $ Left error
5454
Right (js, externs, _) ->
@@ -92,7 +92,9 @@ examples :: [(String, (String, String))]
9292
examples =
9393
[ ("adt",
9494
("Algebraic Data Types",
95-
unlines [ "data Person = Person { name :: String, age :: Number }"
95+
unlines [ "module ADTs where"
96+
, ""
97+
, "data Person = Person { name :: String, age :: Number }"
9698
, ""
9799
, "foreign import numberToString :: Number -> String"
98100
, ""
@@ -101,7 +103,9 @@ examples =
101103
]))
102104
, ("ops",
103105
("Operators",
104-
unlines [ "infixl 5 |>"
106+
unlines [ "module Operators where"
107+
, ""
108+
, "infixl 5 |>"
105109
, ""
106110
, "(|>) :: forall a b c. (a -> b) -> (b -> c) -> a -> c"
107111
, "(|>) f g a = g (f a)"
@@ -113,27 +117,35 @@ examples =
113117
]))
114118
, ("arrays",
115119
("Arrays",
116-
unlines [ "sum (x:xs) = x + sum xs"
120+
unlines [ "module Arrays where"
121+
, ""
122+
, "sum (x:xs) = x + sum xs"
117123
, "sum [] = 0"
118124
, ""
119125
, "sumOfProducts (x : y : xs) = x * y + sum xs"
120126
, "sumOfProducts _ = 0"
121127
]))
122128
, ("rows",
123129
("Row Polymorphism",
124-
unlines [ "showPerson o = o.lastName ++ \", \" ++ o.firstName"
130+
unlines [ "module RowPolymorphism where"
131+
, ""
132+
, "showPerson o = o.lastName ++ \", \" ++ o.firstName"
125133
]))
126134
, ("ffi",
127135
("FFI",
128-
unlines [ "foreign import data IO :: * -> *"
136+
unlines [ "module FFI where"
137+
, ""
138+
, "foreign import data IO :: * -> *"
129139
, ""
130140
, "foreign import console :: { log :: String -> IO { } }"
131141
, ""
132142
, "main = console.log \"Hello World!\""
133143
]))
134144
, ("blocks",
135145
("Mutable Variables",
136-
unlines [ "collatz :: Number -> Number"
146+
unlines [ "module Mutable where"
147+
, ""
148+
, "collatz :: Number -> Number"
137149
, "collatz n ="
138150
, " { "
139151
, " var m = n;"
@@ -151,16 +163,20 @@ examples =
151163
]))
152164
, ("modules",
153165
("Modules",
154-
unlines [ "module Test where"
166+
unlines [ "module M1 where"
155167
, ""
156-
, " incr :: Number -> Number"
157-
, " incr x = x + 1"
168+
, "incr :: Number -> Number"
169+
, "incr x = x + 1"
158170
, ""
159-
, "test = Test.incr 10"
171+
, "module M2 where"
172+
, ""
173+
, "test = M1.incr 10"
160174
]))
161175
, ("rank2",
162176
("Rank N Types",
163-
unlines [ "type Nat = forall a. a -> (a -> a) -> a"
177+
unlines [ "module RankNTypes where"
178+
, ""
179+
, "type Nat = forall a. a -> (a -> a) -> a"
164180
, ""
165181
, "zero :: Nat"
166182
, "zero a _ = a"
@@ -173,6 +189,17 @@ examples =
173189
, "compose :: forall a b c. Lens a b -> Lens b c -> Lens a c"
174190
, "compose l1 l2 f = l2 (l1 f)"
175191
]))
192+
, ("recursion",
193+
("Recursion",
194+
unlines [ "module Recursion where"
195+
, ""
196+
, "isOdd :: Number -> Boolean"
197+
, "isOdd n = !isEven (n - 1)"
198+
, ""
199+
, "isEven :: Number -> Boolean"
200+
, "isEven 0 = true"
201+
, "isEven n = !isOdd (n - 1)"
202+
]))
176203
]
177204

178205
page :: Maybe String -> Maybe Response -> ActionM ()

trypurescript.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ author: Phil Freeman
1313
data-dir: ""
1414

1515
executable trypurescript
16-
build-depends: base ==4.*, scotty -any, purescript ==0.2.1.2, containers -any,
16+
build-depends: base ==4.*, scotty -any, purescript ==0.2.3, containers -any,
1717
mtl -any, blaze-html -any, cmdtheline -any
1818
main-is: Main.hs
1919
buildable: True

0 commit comments

Comments
 (0)