File tree Expand file tree Collapse file tree 3 files changed +18
-27
lines changed Expand file tree Collapse file tree 3 files changed +18
-27
lines changed Original file line number Diff line number Diff line change 1
1
module Main where
2
2
3
- import Prelude ((++))
3
+ data Person = Person String Number
4
4
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
Original file line number Diff line number Diff line change 1
1
module Main where
2
2
3
- foreign import data IO :: * -> *
3
+ import Control.Monad.Eff
4
4
5
- foreign import log " function log(s) { return function() { console.log(s) }; } " :: String -> IO { }
5
+ foreign import data Random :: !
6
6
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
8
15
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ module Main where
2
2
3
3
import Prelude
4
4
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 )
9
9
You can’t perform that action at this time.
0 commit comments