Skip to content

Commit ef9ddac

Browse files
committed
Fix some examples
1 parent 391f0d7 commit ef9ddac

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

examples/adt.purs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
module Main where
22

3-
import Prelude ((++))
3+
data Person = Person String Number
44

5-
class Show a where
6-
show :: a -> String
7-
8-
instance showString :: Show String where
9-
show s = s
10-
11-
instance showBoolean :: Show Boolean where
12-
show true = "true"
13-
show false = "false"
14-
15-
instance showArray :: (Show a) => Show [a] where
16-
show arr = "[" ++ go arr ++ "]"
17-
where
18-
go :: forall a. (Show a) => [a] -> String
19-
go [] = ""
20-
go [x] = show x
21-
go (x:xs) = show x ++ ", " ++ go xs
22-
23-
test = show [true, false]
5+
showPerson :: Person -> String
6+
showPerson (Person name age) =
7+
name ++ ", aged " ++ show age

examples/ffi.purs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
module Main where
22

3-
foreign import data IO :: * -> *
3+
import Control.Monad.Eff
44

5-
foreign import log "function log(s) { return function() { console.log(s) }; }" :: String -> IO { }
5+
foreign import data Random :: !
66

7-
main = log "Hello World!"
7+
foreign import random
8+
"function random() { \
9+
\ return function() { \
10+
\ return Math.random(); \
11+
\ }; \
12+
\}" :: Eff (random :: Random) Number
13+
14+
main = Debug.Trace.print <$> random
815

examples/tco.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module Main where
22

33
import Prelude
44

5-
factHelper prod 0 = prod
6-
factHelper prod n = factHelper (prod * n) (n - 1)
7-
8-
fact = factHelper 1
5+
fact = go 1
6+
where
7+
go prod 0 = prod
8+
go prod n = go (prod * n) (n - 1)
99

0 commit comments

Comments
 (0)