Skip to content

Commit

Permalink
Merge pull request #27 from purescript/compiler/0.12
Browse files Browse the repository at this point in the history
Updates for 0.12
  • Loading branch information
garyb committed May 23, 2018
2 parents 1145444 + 2bde9b5 commit 1de584b
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
/bower_components/
/node_modules/
/output/
package-lock.json
38 changes: 22 additions & 16 deletions LICENSE
@@ -1,20 +1,26 @@
The MIT License (MIT)
Copyright 2018 PureScript

Copyright (c) 2014 PureScript
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 changes: 10 additions & 7 deletions bower.json
@@ -1,13 +1,12 @@
{
"name": "purescript-profunctor",
"homepage": "https://github.com/purescript/purescript-profunctor",
"description": "Profunctor typeclass for PureScript",
"authors": [
"Hardy Jones <jones3.hardy@gmail.com>",
"Sean Chalmers <sclhiannan@gmail.com>",
"Phil Freeman <paf31@cantab.net>"
],
"license": "MIT",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "git://github.com/purescript/purescript-profunctor.git"
Expand All @@ -22,10 +21,14 @@
"package.json"
],
"dependencies": {
"purescript-contravariant": "^3.0.0",
"purescript-distributive": "^3.0.0",
"purescript-either": "^3.0.0",
"purescript-exists": "^3.0.0",
"purescript-tuples": "^4.0.0"
"purescript-contravariant": "^4.0.0",
"purescript-control": "^4.0.0",
"purescript-distributive": "^4.0.0",
"purescript-either": "^4.0.0",
"purescript-exists": "^4.0.0",
"purescript-invariant": "^4.0.0",
"purescript-newtype": "^3.0.0",
"purescript-prelude": "^4.0.0",
"purescript-tuples": "^5.0.0"
}
}
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -5,8 +5,8 @@
"build": "pulp build -- --censor-lib --strict"
},
"devDependencies": {
"pulp": "^10.0.4",
"purescript-psa": "^0.5.0-rc.1",
"rimraf": "^2.6.1"
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
12 changes: 6 additions & 6 deletions src/Data/Profunctor.purs
Expand Up @@ -17,27 +17,27 @@ import Data.Newtype (class Newtype, wrap, unwrap)
-- |
-- | Laws:
-- |
-- | - Identity: `dimap id id = id`
-- | - Identity: `dimap identity identity = identity`
-- | - Composition: `dimap f1 g1 <<< dimap f2 g2 = dimap (f1 >>> f2) (g1 <<< g2)`
class Profunctor p where
dimap :: forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d

-- | Map a function over the (contravariant) first type argument only.
lmap :: forall a b c p. Profunctor p => (a -> b) -> p b c -> p a c
lmap a2b = dimap a2b id
lcmap :: forall a b c p. Profunctor p => (a -> b) -> p b c -> p a c
lcmap a2b = dimap a2b identity

-- | Map a function over the (covariant) second type argument only.
rmap :: forall a b c p. Profunctor p => (b -> c) -> p a b -> p a c
rmap b2c = dimap id b2c
rmap b2c = dimap identity b2c

-- | Lift a pure function into any `Profunctor` which is also a `Category`.
arr :: forall a b p. Category p => Profunctor p => (a -> b) -> p a b
arr f = rmap f id
arr f = rmap f identity

unwrapIso :: forall p t a. Profunctor p => Newtype t a => p t t -> p a a
unwrapIso = dimap wrap unwrap

wrapIso :: forall p t a. Profunctor p => Newtype t a => (t -> a) -> p a a -> p t t
wrapIso :: forall p t a. Profunctor p => Newtype t a => (a -> t) -> p a a -> p t t
wrapIso _ = dimap unwrap wrap

instance profunctorFn :: Profunctor (->) where
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Profunctor/Choice.purs
Expand Up @@ -81,6 +81,6 @@ fanin
fanin l r = (l +++ r) >>> join
where
join :: p (Either c c) c
join = dimap (either id id) id id
join = dimap (either identity identity) identity identity

infixr 2 fanin as |||
10 changes: 5 additions & 5 deletions src/Data/Profunctor/Costar.purs
Expand Up @@ -9,7 +9,7 @@ import Data.Distributive (class Distributive, distribute)
import Data.Either (Either(..), either)
import Data.Functor.Invariant (class Invariant, imapF)
import Data.Newtype (class Newtype)
import Data.Profunctor (class Profunctor, lmap)
import Data.Profunctor (class Profunctor, lcmap)
import Data.Profunctor.Closed (class Closed)
import Data.Profunctor.Cochoice (class Cochoice)
import Data.Profunctor.Costrong (class Costrong)
Expand All @@ -27,7 +27,7 @@ instance semigroupoidCostar :: Extend f => Semigroupoid (Costar f) where
compose (Costar f) (Costar g) = Costar (f =<= g)

instance categoryCostar :: Comonad f => Category (Costar f) where
id = Costar extract
identity = Costar extract

instance functorCostar :: Functor (Costar f a) where
map f (Costar g) = Costar (f <<< g)
Expand Down Expand Up @@ -65,14 +65,14 @@ instance costrongCostar :: Functor f => Costrong (Costar f) where

instance cochoiceCostar :: Applicative f => Cochoice (Costar f) where
unleft (Costar f) =
let g = either id (\r -> g (pure (Right r))) <<< f
let g = either identity (\r -> g (pure (Right r))) <<< f
in Costar (g <<< map Left)
unright (Costar f) =
let g = either (\l -> g (pure (Left l))) id <<< f
let g = either (\l -> g (pure (Left l))) identity <<< f
in Costar (g <<< map Right)

instance closedCostar :: Functor f => Closed (Costar f) where
closed (Costar f) = Costar \g x -> f (map (_ $ x) g)

hoistCostar :: forall f g a b. (g ~> f) -> Costar f a b -> Costar g a b
hoistCostar f (Costar g) = Costar (lmap f g)
hoistCostar f (Costar g) = Costar (lcmap f g)
4 changes: 2 additions & 2 deletions src/Data/Profunctor/Cowrap.purs
Expand Up @@ -4,7 +4,7 @@ import Prelude

import Data.Newtype (class Newtype)
import Data.Functor.Contravariant (class Contravariant)
import Data.Profunctor (class Profunctor, lmap)
import Data.Profunctor (class Profunctor, lcmap)

-- | Provides a `Contravariant` over the first argument of a `Profunctor`.
newtype Cowrap p b a = Cowrap (p a b)
Expand All @@ -17,4 +17,4 @@ instance showCowrap :: Show (p a b) => Show (Cowrap p b a) where
show (Cowrap x) = "(Cowrap " <> show x <> ")"

instance contravariantCowrap :: Profunctor p => Contravariant (Cowrap p b) where
cmap f (Cowrap a) = Cowrap (lmap f a)
cmap f (Cowrap a) = Cowrap (lcmap f a)
3 changes: 1 addition & 2 deletions src/Data/Profunctor/Join.purs
Expand Up @@ -5,7 +5,6 @@ import Prelude
import Data.Functor.Invariant (class Invariant)
import Data.Newtype (class Newtype)
import Data.Profunctor (class Profunctor, dimap)
import Data.Monoid (class Monoid)

-- | Turns a `Profunctor` into a `Invariant` functor by equating the two type
-- | arguments.
Expand All @@ -22,7 +21,7 @@ instance semigroupJoin :: Semigroupoid p => Semigroup (Join p a) where
append (Join a) (Join b) = Join (a <<< b)

instance monoidJoin :: Category p => Monoid (Join p a) where
mempty = Join id
mempty = Join identity

instance invariantJoin :: Profunctor p => Invariant (Join p) where
imap f g (Join a) = Join (dimap g f a)
2 changes: 1 addition & 1 deletion src/Data/Profunctor/Split.purs
Expand Up @@ -30,7 +30,7 @@ unSplit :: forall f a b r. (forall x. (a -> x) -> (x -> b) -> f x -> r) -> Split
unSplit f (Split e) = runExists (\(SplitF g h fx) -> f g h fx) e

liftSplit :: forall f a. f a -> Split f a a
liftSplit = split id id
liftSplit = split identity identity

lowerSplit :: forall f a. Invariant f => Split f a a -> f a
lowerSplit = unSplit (flip imap)
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Profunctor/Star.purs
Expand Up @@ -29,7 +29,7 @@ instance semigroupoidStar :: Bind f => Semigroupoid (Star f) where
compose (Star f) (Star g) = Star \x -> g x >>= f

instance categoryStar :: Monad f => Category (Star f) where
id = Star pure
identity = Star pure

instance functorStar :: Functor f => Functor (Star f a) where
map f (Star g) = Star (map f <<< g)
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Profunctor/Strong.purs
Expand Up @@ -78,6 +78,6 @@ fanout
fanout l r = split >>> (l *** r)
where
split :: p a (Tuple a a)
split = dimap id (\a -> Tuple a a) id
split = dimap identity (\a -> Tuple a a) identity

infixr 3 fanout as &&&

0 comments on commit 1de584b

Please sign in to comment.