Skip to content

Commit 411b32a

Browse files
committed
Update examples and prelude for 0.5
1 parent 2471297 commit 411b32a

File tree

4 files changed

+77
-25
lines changed

4 files changed

+77
-25
lines changed

Main.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ data Compiled = Compiled { js :: String
5656
data Response = Response (Either String Compiled)
5757

5858
options :: P.Options
59-
options = P.defaultOptions { P.optionsModules = ["Main"] }
59+
options = P.defaultOptions { P.optionsModules = ["Main"]
60+
, P.optionsBrowserNamespace = Just "PS"
61+
}
6062

6163
compile :: [P.Module] -> String -> IO Response
6264
compile _ input | length input > 5000 = return $ Response $ Left "Please limit your input to 5000 characters"
@@ -190,3 +192,4 @@ termInfo = defTI
190192
main :: IO ()
191193
main = run (term, termInfo)
192194

195+

examples/do.purs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
module Main where
22

3-
import Prelude
4-
53
data Maybe a = Nothing | Just a
64

7-
instance monadMaybe :: Prelude.Monad Maybe where
8-
return = Just
5+
--
6+
-- In order to define an instance of Monad for the Maybe type,
7+
-- we need to provide instaces for its superclasses:
8+
-- Functor, Apply, Applicative and Bind.
9+
--
10+
11+
instance functorMaybe :: Functor Maybe where
12+
(<$>) _ Nothing = Nothing
13+
(<$>) f (Just a) = Just a
14+
15+
instance applyMaybe :: Apply Maybe where
16+
(<*>) = ap
17+
18+
instance applicativeMaybe :: Applicative Maybe where
19+
pure = Just
20+
21+
instance bindMaybe :: Bind Maybe where
922
(>>=) Nothing _ = Nothing
10-
(>>=) (Just a) f = f a
23+
(>>=) (Just a) f = f a
24+
25+
instance monadMaybe :: Monad Maybe
26+
27+
--
28+
-- In this example, we find the sum of two numbers, using the guard
29+
-- function to make sure the sum is even.
30+
--
1131

12-
isEven n | n % 2 == 0 = Just {}
13-
isEven _ = Nothing
32+
guard :: Boolean -> Maybe {}
33+
guard true = Just {}
34+
guard false = Nothing
1435

36+
evenSum :: Maybe Number -> Maybe Number -> Maybe Number
1537
evenSum a b = do
1638
n <- a
1739
m <- b
1840
let sum = n + m
19-
isEven sum
41+
guard $ sum % 2 == 0
2042
return sum
2143

prelude/prelude.purs

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module Prelude where
2-
import Prelude ()
32
infixr 9 >>>
43
infixr 9 <<<
54
infixr 0 $
65
infixl 0 #
6+
infixr 6 :
77
infixl 4 <$>
88
infixl 4 <*>
99
infixl 3 <|>
@@ -22,11 +22,13 @@ infixl 4 >=
2222
infixl 10 &
2323
infixl 10 |
2424
infixl 10 ^
25-
infixl 8 !!
2625
infixr 2 ||
2726
infixr 3 &&
27+
infixr 5 <>
2828
infixr 5 ++
2929
data Ordering = LT | GT | EQ
30+
class Semigroup a where
31+
(<>) :: a -> a -> a
3032
class BoolLike b where
3133
(&&) :: b -> b -> b
3234
(||) :: b -> b -> b
@@ -39,7 +41,7 @@ class Bits b where
3941
shr :: b -> Prim.Number -> b
4042
zshr :: b -> Prim.Number -> b
4143
complement :: b -> b
42-
class Ord a where
44+
class (Prelude.Eq a) <= Ord a where
4345
compare :: a -> a -> Prelude.Ordering
4446
class Eq a where
4547
(==) :: a -> a -> Prim.Boolean
@@ -51,27 +53,29 @@ class Num a where
5153
(/) :: a -> a -> a
5254
(%) :: a -> a -> a
5355
negate :: a -> a
54-
class Monad m where
55-
return :: forall a. a -> m a
56+
class (Prelude.Applicative m, Prelude.Bind m) <= Monad m where
57+
class (Prelude.Apply m) <= Bind m where
5658
(>>=) :: forall a b. m a -> (a -> m b) -> m b
5759
class Alternative f where
5860
empty :: forall a. f a
5961
(<|>) :: forall a. f a -> f a -> f a
60-
class Applicative f where
62+
class (Prelude.Apply f) <= Applicative f where
6163
pure :: forall a. a -> f a
64+
class (Prelude.Functor f) <= Apply f where
6265
(<*>) :: forall a b. f (a -> b) -> f a -> f b
6366
class Functor f where
6467
(<$>) :: forall a b. (a -> b) -> f a -> f b
6568
class Show a where
6669
show :: a -> Prim.String
67-
class Category a where
70+
class (Prelude.Semigroupoid a) <= Category a where
6871
id :: forall t. a t t
72+
class Semigroupoid a where
6973
(<<<) :: forall b c d. a c d -> a b c -> a b d
70-
foreign import (++) :: Prim.String -> Prim.String -> Prim.String
74+
foreign import (++) :: forall s. (Prelude.Semigroup s) => s -> s -> s
75+
foreign import concatString :: Prim.String -> Prim.String -> Prim.String
7176
foreign import boolNot :: Prim.Boolean -> Prim.Boolean
7277
foreign import boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
7378
foreign import boolAnd :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
74-
foreign import (!!) :: forall a. [a] -> Prim.Number -> a
7579
foreign import numComplement :: Prim.Number -> Prim.Number
7680
foreign import numXor :: Prim.Number -> Prim.Number -> Prim.Number
7781
foreign import numOr :: Prim.Number -> Prim.Number -> Prim.Number
@@ -92,28 +96,44 @@ foreign import numDiv :: Prim.Number -> Prim.Number -> Prim.Number
9296
foreign import numMul :: Prim.Number -> Prim.Number -> Prim.Number
9397
foreign import numSub :: Prim.Number -> Prim.Number -> Prim.Number
9498
foreign import numAdd :: Prim.Number -> Prim.Number -> Prim.Number
99+
foreign import ap :: forall m a b. (Prelude.Monad m) => m (a -> b) -> m a -> m b
100+
foreign import liftM1 :: forall m a b. (Prelude.Monad m) => (a -> b) -> m a -> m b
101+
foreign import return :: forall m a. (Prelude.Monad m) => a -> m a
102+
foreign import liftA1 :: forall f a b. (Prelude.Applicative f) => (a -> b) -> f a -> f b
103+
foreign import showArrayImpl :: forall a. (a -> Prim.String) -> [a] -> Prim.String
95104
foreign import showNumberImpl :: Prim.Number -> Prim.String
105+
foreign import showStringImpl :: Prim.String -> Prim.String
106+
foreign import cons :: forall a. a -> [a] -> [a]
107+
foreign import (:) :: forall a. a -> [a] -> [a]
96108
foreign import (#) :: forall a b. a -> (a -> b) -> b
97109
foreign import ($) :: forall a b. (a -> b) -> a -> b
98-
foreign import (>>>) :: forall a b c d. (Prelude.Category a) => a b c -> a c d -> a b d
99-
foreign import on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
110+
foreign import (>>>) :: forall a b c d. (Prelude.Semigroupoid a) => a b c -> a c d -> a b d
111+
foreign import asTypeOf :: forall a. a -> a -> a
100112
foreign import const :: forall a b. a -> b -> a
101113
foreign import flip :: forall a b c. (a -> b -> c) -> b -> a -> c
114+
foreign import instance semigroupoidArr :: Prelude.Semigroupoid Prim.Function
102115
foreign import instance categoryArr :: Prelude.Category Prim.Function
103116
foreign import instance showString :: Prelude.Show Prim.String
104117
foreign import instance showBoolean :: Prelude.Show Prim.Boolean
105118
foreign import instance showNumber :: Prelude.Show Prim.Number
106-
foreign import instance functorFromApplicative :: (Prelude.Applicative f) => Prelude.Functor f
107-
foreign import instance applicativeFromMonad :: (Prelude.Monad m) => Prelude.Applicative m
119+
foreign import instance showArray :: (Prelude.Show a) => Prelude.Show [a]
108120
foreign import instance numNumber :: Prelude.Num Prim.Number
109121
foreign import instance eqString :: Prelude.Eq Prim.String
110122
foreign import instance eqNumber :: Prelude.Eq Prim.Number
111123
foreign import instance eqBoolean :: Prelude.Eq Prim.Boolean
112124
foreign import instance eqArray :: (Prelude.Eq a) => Prelude.Eq [a]
125+
foreign import instance eqOrdering :: Prelude.Eq Prelude.Ordering
113126
foreign import instance showOrdering :: Prelude.Show Prelude.Ordering
114127
foreign import instance ordNumber :: Prelude.Ord Prim.Number
115128
foreign import instance bitsNumber :: Prelude.Bits Prim.Number
116129
foreign import instance boolLikeBoolean :: Prelude.BoolLike Prim.Boolean
130+
foreign import instance semigroupString :: Prelude.Semigroup Prim.String
131+
module Prelude.Unsafe where
132+
import Prelude ()
133+
foreign import unsafeIndex :: forall a. [a] -> Prim.Number -> a
134+
module Data.Function where
135+
import Prelude ()
136+
foreign import on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
117137
module Data.Eq where
118138
import Prelude ()
119139
data Ref a = Ref a
@@ -128,14 +148,20 @@ foreign import forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> C
128148
foreign import whileE :: forall e a. Control.Monad.Eff.Eff e Prim.Boolean -> Control.Monad.Eff.Eff e a -> Control.Monad.Eff.Eff e { }
129149
foreign import untilE :: forall e. Control.Monad.Eff.Eff e Prim.Boolean -> Control.Monad.Eff.Eff e { }
130150
foreign import runPure :: forall a. Control.Monad.Eff.Pure a -> a
131-
foreign import bindEff :: forall e a b. Control.Monad.Eff.Eff e a -> (a -> Control.Monad.Eff.Eff e b) -> Control.Monad.Eff.Eff e b
132-
foreign import retEff :: forall e a. a -> Control.Monad.Eff.Eff e a
151+
foreign import bindE :: forall e a b. Control.Monad.Eff.Eff e a -> (a -> Control.Monad.Eff.Eff e b) -> Control.Monad.Eff.Eff e b
152+
foreign import returnE :: forall e a. a -> Control.Monad.Eff.Eff e a
153+
foreign import instance functorEff :: Prelude.Functor (Control.Monad.Eff.Eff e)
154+
foreign import instance applyEff :: Prelude.Apply (Control.Monad.Eff.Eff e)
155+
foreign import instance applicativeEff :: Prelude.Applicative (Control.Monad.Eff.Eff e)
156+
foreign import instance bindEff :: Prelude.Bind (Control.Monad.Eff.Eff e)
133157
foreign import instance monadEff :: Prelude.Monad (Control.Monad.Eff.Eff e)
134158
module Control.Monad.Eff.Unsafe where
135159
import Prelude ()
160+
import Control.Monad.Eff ()
136161
foreign import unsafeInterleaveEff :: forall eff1 eff2 a. Control.Monad.Eff.Eff eff1 a -> Control.Monad.Eff.Eff eff2 a
137162
module Control.Monad.ST where
138163
import Prelude ()
164+
import Control.Monad.Eff ()
139165
foreign import data STArray :: * -> * -> *
140166
foreign import data STRef :: * -> * -> *
141167
foreign import data ST :: * -> !
@@ -150,6 +176,7 @@ foreign import readSTRef :: forall a h r. Control.Monad.ST.STRef h a -> Control.
150176
foreign import newSTRef :: forall a h r. a -> Control.Monad.Eff.Eff (st :: Control.Monad.ST.ST h | r) (Control.Monad.ST.STRef h a)
151177
module Debug.Trace where
152178
import Prelude ()
179+
import Control.Monad.Eff ()
153180
foreign import data Trace :: !
154181
foreign import print :: forall a r. (Prelude.Show a) => a -> Control.Monad.Eff.Eff (trace :: Debug.Trace.Trace | r) { }
155182
foreign import trace :: forall r. Prim.String -> Control.Monad.Eff.Eff (trace :: Debug.Trace.Trace | r) { }

trypurescript.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ data-dir: ""
1515
executable trypurescript
1616
build-depends: blaze-markup >=0.5.1.5 && <0.6,
1717
bytestring >=0.10.0.2 && <0.11, base ==4.*, scotty -any,
18-
purescript ==0.4.11.1, containers -any, mtl -any, blaze-html -any,
18+
purescript ==0.5.0, containers -any, mtl -any, blaze-html -any,
1919
cmdtheline -any, monad-unify >=0.2.1 && <0.3, utf8-string -any,
2020
file-embed >=0.0.6
2121
main-is: Main.hs

0 commit comments

Comments
 (0)