Skip to content

Commit cb60f2a

Browse files
committed
Merge pull request #5 from ethul/topic/purescript-0.9
Updates for PureScript 0.9.1
2 parents d51531b + 3b75829 commit cb60f2a

5 files changed

Lines changed: 34 additions & 36 deletions

File tree

bower.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
"url": "git://github.com/ethul/purescript-freeap.git"
1111
},
1212
"dependencies": {
13-
"purescript-exists": "~0.2.0",
14-
"purescript-const": "~0.5.0"
13+
"purescript-exists": "^1.0.0",
14+
"purescript-const": "^1.0.0"
1515
},
1616
"devDependencies": {
17-
"purescript-either": "~0.2.3",
18-
"purescript-integers": "~0.2.1",
19-
"purescript-generics": "~0.6.2",
20-
"purescript-console": "~0.1.1"
17+
"purescript-either": "^1.0.0",
18+
"purescript-integers": "^1.0.0",
19+
"purescript-generics": "^1.0.0",
20+
"purescript-console": "^1.0.0",
21+
"purescript-exceptions": "~1.0.0"
2122
}
2223
}

src/Control/Applicative/Free.purs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
module Control.Applicative.Free
2-
( FreeAp()
3-
, NaturalTransformation()
2+
( FreeAp
43
, liftFreeAp
54
, retractFreeAp
65
, foldFreeAp
76
, hoistFreeAp
87
, analyzeFreeAp
98
) where
109

11-
import Prelude (Applicative, Apply, Functor, Unit(), (<<<), apply, flip, id, map, pure, unit)
10+
import Prelude (class Applicative, class Apply, class Functor, type (~>), Unit, (<<<), apply, flip, id, map, pure, unit)
1211

13-
import Data.Const (Const(..), getConst)
14-
import Data.Exists (Exists(), mkExists, runExists)
15-
import Data.Monoid (Monoid)
12+
import Data.Const (Const(Const), getConst)
13+
import Data.Exists (Exists, mkExists, runExists)
14+
import Data.Monoid (class Monoid)
1615

1716
-- | The free applicative functor for a type constructor `f`.
1817
data FreeAp f a = Pure a | Ap (Exists (ApF f a))
1918

2019
data ApF f a i = ApF (Unit -> f i) (Unit -> FreeAp f (i -> a))
2120

22-
type NaturalTransformation f g = forall a. f a -> g a
23-
2421
ap :: forall f a i. (Unit -> f i) -> (Unit -> FreeAp f (i -> a)) -> FreeAp f a
2522
ap v k = Ap (mkExists (ApF v k))
2623

@@ -37,13 +34,13 @@ retractFreeAp (Ap x) = runExists (\(ApF v k') -> apply (retractFreeAp (k' unit))
3734

3835
-- | Run a free applicative functor with a natural transformation from
3936
-- | the type constructor `f` to the applicative functor `g`.
40-
foldFreeAp :: forall f g a. (Applicative g) => NaturalTransformation f g -> FreeAp f a -> g a
37+
foldFreeAp :: forall f g a. (Applicative g) => (f ~> g) -> FreeAp f a -> g a
4138
foldFreeAp k (Pure a) = pure a
4239
foldFreeAp k (Ap x) = runExists (\(ApF v k') -> apply (map (flip id) (k (v unit))) (foldFreeAp k (k' unit))) x
4340

4441
-- | Natural transformation from `FreeAp f a` to `FreeAp g a` given a
4542
-- | natural transformation from `f` to `g`.
46-
hoistFreeAp :: forall f g a. NaturalTransformation f g -> FreeAp f a -> FreeAp g a
43+
hoistFreeAp :: forall f g a. (f ~> g) -> FreeAp f a -> FreeAp g a
4744
hoistFreeAp k (Pure a) = Pure a
4845
hoistFreeAp k (Ap x) = runExists (\(ApF v k') -> ap (\_ -> k (v unit)) (\_ -> hoistFreeAp k (k' unit))) x
4946

test/Test/Control/Applicative/Free.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module Test.Control.Applicative.Free
22
( checkAnalyze
33
) where
44

5-
import Prelude (Unit(), (==), (++), unit, apply, map)
6-
import Control.Applicative.Free (FreeAp(), liftFreeAp, analyzeFreeAp)
5+
import Prelude (Unit, (==), (<>), unit, apply, map)
6+
import Control.Applicative.Free (FreeAp, liftFreeAp, analyzeFreeAp)
77
import Data.Either (Either(..))
88

99
data M r = A r | B r
@@ -28,4 +28,4 @@ expected = "AB"
2828
checkAnalyze :: Either String String
2929
checkAnalyze = if result == expected
3030
then Right result
31-
else Left (result ++ " is not " ++ expected)
31+
else Left (result <> " is not " <> expected)

test/Test/Control/Applicative/Free/Validation.purs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module Test.Control.Applicative.Free.Validation
2-
( User()
2+
( User
33
, runForm
44
) where
55

6-
import Prelude (Show, show, (<<<), (==), (<$>), (<*>), (++))
6+
import Prelude (class Show, show, (<<<), (==), (<$>), (<*>), (<>))
77

8-
import Control.Applicative.Free (FreeAp(), foldFreeAp, liftFreeAp)
8+
import Control.Applicative.Free (FreeAp, foldFreeAp, liftFreeAp)
9+
import Control.Monad.Eff.Exception.Unsafe (unsafeThrow)
910

1011
import Data.Either (Either(..))
1112
import Data.Int (fromString)
1213
import Data.Maybe (maybe)
13-
import Data.Maybe.Unsafe (unsafeThrow)
1414

1515
type Validator a = String -> Either String a
1616

@@ -22,10 +22,10 @@ field :: forall a. String -> Validator a -> Form a
2222
field n v = liftFreeAp (Field { name: n, validator: v })
2323

2424
nes :: String -> Form String
25-
nes n = field n (\v -> if v == "" then Left (n ++ ": Invalid NES") else Right v)
25+
nes n = field n (\v -> if v == "" then Left (n <> ": Invalid NES") else Right v)
2626

2727
int :: String -> Form Int
28-
int n = field n (maybe (Left (n ++ ": Invalid Int")) Right <<< fromString)
28+
int n = field n (maybe (Left (n <> ": Invalid Int")) Right <<< fromString)
2929

3030
newtype User = User { firstName :: String, lastName :: String, age :: Int }
3131

@@ -48,7 +48,7 @@ runForm first last age =
4848
"First name" -> v first
4949
"Last name" -> v last
5050
"Age" -> v age
51-
_ -> unsafeThrow ("Unexpected field: " ++ n)
51+
_ -> unsafeThrow ("Unexpected field: " <> n)
5252

5353
instance showUser :: Show User where
54-
show (User m) = m.firstName ++ " " ++ m.lastName ++ " " ++ show m.age
54+
show (User m) = m.firstName <> " " <> m.lastName <> " " <> show m.age

test/Test/Main.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module Test.Main where
22

3-
import Prelude (Unit(), bind)
3+
import Prelude (Unit, bind)
44

5-
import Control.Monad.Eff (Eff())
6-
import Control.Monad.Eff.Console (CONSOLE(), log, print)
5+
import Control.Monad.Eff (Eff)
6+
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
77

8-
import qualified Test.Control.Applicative.Free.Validation as Validation
9-
import qualified Test.Control.Applicative.Free as FreeTest
8+
import Test.Control.Applicative.Free.Validation as Validation
9+
import Test.Control.Applicative.Free as FreeTest
1010

1111
main :: Eff (console :: CONSOLE) Unit
1212
main = do
1313
log "\nvalid case:"
14-
print (Validation.runForm "Joe" "Smith" "28")
14+
logShow (Validation.runForm "Joe" "Smith" "28")
1515

1616
log "\nempty last name:"
17-
print (Validation.runForm "Larry" "" "45")
17+
logShow (Validation.runForm "Larry" "" "45")
1818

1919
log "\ninvalid age:"
20-
print (Validation.runForm "Sue" "Larry" "A")
20+
logShow (Validation.runForm "Sue" "Larry" "A")
2121

2222
log "\nanalyze:"
23-
print FreeTest.checkAnalyze
23+
logShow FreeTest.checkAnalyze

0 commit comments

Comments
 (0)