Skip to content

Prepare for 2.0 release #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"package.json"
],
"dependencies": {
"purescript-distributive": "^1.0.0",
"purescript-either": "^1.0.0",
"purescript-tuples": "^1.0.0"
"purescript-distributive": "^2.0.0",
"purescript-either": "^2.0.0",
"purescript-tuples": "^3.0.0"
}
}
7 changes: 7 additions & 0 deletions src/Data/Profunctor.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Data.Profunctor where

import Prelude
import Data.Newtype (class Newtype, wrap, unwrap)

-- | A `Profunctor` is a `Functor` from the pair category `(Type^op, Type)`
-- | to `Type`.
Expand Down Expand Up @@ -33,5 +34,11 @@ rmap b2c = dimap id b2c
arr :: forall a b p. (Category p, Profunctor p) => (a -> b) -> p a b
arr f = rmap f id

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 _ = dimap unwrap wrap

instance profunctorFn :: Profunctor (->) where
dimap a2b c2d b2c = a2b >>> b2c >>> c2d
11 changes: 5 additions & 6 deletions src/Data/Profunctor/Costar.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Control.Extend (class Extend, (=<=))
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)
import Data.Profunctor.Closed (class Closed)
import Data.Profunctor.Cochoice (class Cochoice)
Expand All @@ -20,9 +21,7 @@ import Data.Tuple (Tuple(..), fst, snd)
-- | `Costar f` is also the co-Kleisli category for `f`.
newtype Costar f b a = Costar (f b -> a)

-- | Unwrap a value of type `Costar f a b`.
unCostar :: forall f a b. Costar f b a -> f b -> a
unCostar (Costar f) = f
derive instance newtypeCostar :: Newtype (Costar f a b) _

instance semigroupoidCostar :: Extend f => Semigroupoid (Costar f) where
compose (Costar f) (Costar g) = Costar (f =<= g)
Expand All @@ -43,12 +42,12 @@ instance applicativeCostar :: Applicative (Costar f a) where
pure a = Costar \_ -> a

instance bindCostar :: Bind (Costar f a) where
bind (Costar m) f = Costar \x -> unCostar (f (m x)) x
bind (Costar m) f = Costar \x -> case f (m x) of Costar g -> g x

instance monadCostar :: Monad (Costar f a)

instance distributiveCostar :: Distributive f => Distributive (Costar f a) where
distribute f = Costar \g -> map ((_ $ g) <<< unCostar) f
instance distributiveCostar :: Distributive (Costar f a) where
distribute f = Costar \a -> map (\(Costar g) -> g a) f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the Distributive constraint on f here?

collect f = distribute <<< map f

instance profunctorCostar :: Functor f => Profunctor (Costar f) where
Expand Down
9 changes: 4 additions & 5 deletions src/Data/Profunctor/Star.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Control.Plus (class Plus, empty)
import Data.Distributive (class Distributive, distribute, collect)
import Data.Either (Either(..), either)
import Data.Functor.Invariant (class Invariant, imap)
import Data.Newtype (class Newtype)
import Data.Profunctor (class Profunctor)
import Data.Profunctor.Choice (class Choice)
import Data.Profunctor.Closed (class Closed)
Expand All @@ -22,9 +23,7 @@ import Data.Tuple (Tuple(..))
-- | `Star f` is also the Kleisli category for `f`
newtype Star f a b = Star (a -> f b)

-- | Unwrap a value of type `Star f a b`.
unStar :: forall f a b. Star f a b -> a -> f b
unStar (Star f) = f
derive instance newtypeStar :: Newtype (Star f a b) _

instance semigroupoidStar :: Bind f => Semigroupoid (Star f) where
compose (Star f) (Star g) = Star \x -> g x >>= f
Expand All @@ -45,7 +44,7 @@ instance applicativeStar :: Applicative f => Applicative (Star f a) where
pure a = Star \_ -> pure a

instance bindStar :: Bind f => Bind (Star f a) where
bind (Star m) f = Star \x -> m x >>= \a -> unStar (f a) x
bind (Star m) f = Star \x -> m x >>= \a -> case f a of Star g -> g x

instance monadStar :: Monad f => Monad (Star f a)

Expand All @@ -62,7 +61,7 @@ instance monadZeroStar :: MonadZero f => MonadZero (Star f a)
instance monadPlusStar :: MonadPlus f => MonadPlus (Star f a)

instance distributiveStar :: Distributive f => Distributive (Star f a) where
distribute f = Star \a -> collect ((_ $ a) <<< unStar) f
distribute f = Star \a -> collect (\(Star g) -> g a) f
collect f = distribute <<< map f

instance profunctorStar :: Functor f => Profunctor (Star f) where
Expand Down