1- {-# LANGUAGE GADTs #-}
21{-# LANGUAGE FlexibleContexts #-}
32{-# LANGUAGE FlexibleInstances #-}
4- {-# LANGUAGE KindSignatures #-}
53{-# LANGUAGE LambdaCase #-}
64{-# LANGUAGE LinearTypes #-}
75{-# LANGUAGE MultiParamTypeClasses #-}
86{-# LANGUAGE NoImplicitPrelude #-}
9- {-# LANGUAGE RankNTypes #-}
107{-# LANGUAGE TupleSections #-}
118{-# LANGUAGE TypeOperators #-}
129
@@ -16,8 +13,7 @@ module Data.Profunctor.Linear
1613 ( Profunctor (.. )
1714 , Monoidal (.. )
1815 , Strong (.. )
19- , PWandering (.. )
20- , DWandering (.. )
16+ , Traversing
2117 , LinearArrow (.. ), getLA
2218 , Exchange (.. )
2319 , Market (.. ), runMarket
@@ -35,7 +31,7 @@ import Control.Arrow (Kleisli(..))
3531
3632-- TODO: write laws
3733
38- class Profunctor ( arr :: * -> * -> * ) where
34+ class Profunctor arr where
3935 {-# MINIMAL dimap | lmap, rmap #-}
4036
4137 dimap :: (s ->. a ) -> (b ->. t ) -> a `arr ` b -> s `arr ` t
@@ -65,17 +61,7 @@ class (SymmetricMonoidal m u, Profunctor arr) => Strong m u arr where
6561 second arr = dimap swap swap (first arr)
6662 {-# INLINE second #-}
6763
68- -- XXX: Just as Prelude.Functor/Data.Functor will combine into
69- -- > `class Functor (p :: Multiplicity) f`
70- -- so will Traversable, and then we would instead write
71- -- > class (...) => Wandering (p :: Multiplicity) arr where
72- -- > wander :: Traversable p f => a `arr` b -> f a `arr` f b
73- -- For now, however, we cannot do this, so we use two classes instead:
74- -- PreludeWandering and DataWandering
75- class (Strong (,) () arr , Strong Either Void arr ) => PWandering arr where
76- pwander :: Prelude. Traversable f => a `arr ` b -> f a `arr ` f b
77- class (Strong (,) () arr , Strong Either Void arr ) => DWandering arr where
78- dwander :: Data. Traversable f => a `arr ` b -> f a `arr ` f b
64+ class (Strong (,) () arr , Strong Either Void arr , Monoidal (,) () arr ) => Traversing arr where
7965
8066---------------
8167-- Instances --
@@ -97,8 +83,11 @@ instance Strong Either Void LinearArrow where
9783 first (LA f) = LA $ either (Left . f) Right
9884 second (LA g) = LA $ either Left (Right . g)
9985
100- instance DWandering LinearArrow where
101- dwander (LA f) = LA (Data. fmap f)
86+ instance Monoidal (,) () LinearArrow where
87+ LA f *** LA g = LA $ \ (a,x) -> (f a, g x)
88+ unit = LA id
89+
90+ instance Traversing LinearArrow
10291
10392instance Profunctor (-> ) where
10493 dimap f g h x = g (h (f x))
@@ -107,8 +96,10 @@ instance Strong (,) () (->) where
10796instance Strong Either Void (-> ) where
10897 first f (Left x) = Left (f x)
10998 first _ (Right y) = Right y
110- instance PWandering (-> ) where
111- pwander = Prelude. fmap
99+ instance Monoidal (,) () (-> ) where
100+ (f *** g) (a,x) = (f a, g x)
101+ unit () = ()
102+ instance Traversing (-> )
112103
113104data Exchange a b s t = Exchange (s ->. a ) (b ->. t )
114105instance Profunctor (Exchange a b ) where
@@ -126,6 +117,12 @@ instance Prelude.Applicative f => Strong Either Void (Kleisli f) where
126117 Left x -> Prelude. fmap Left (f x)
127118 Right y -> Prelude. pure (Right y)
128119
120+ instance Prelude. Applicative f => Monoidal (,) () (Kleisli f ) where
121+ Kleisli f *** Kleisli g = Kleisli (\ (x,y) -> (,) Prelude. <$> f x Prelude. <*> g y)
122+ unit = Kleisli Prelude. pure
123+
124+ instance Prelude. Applicative f => Traversing (Kleisli f ) where
125+
129126data Market a b s t = Market (b ->. t ) (s ->. Either t a )
130127runMarket :: Market a b s t ->. (b ->. t , s ->. Either t a )
131128runMarket (Market f g) = (f, g)
@@ -136,8 +133,11 @@ instance Profunctor (Market a b) where
136133instance Strong Either Void (Market a b ) where
137134 first (Market f g) = Market (Left . f) (either (either (Left . Left ) Right . g) (Left . Right ))
138135
139- instance Prelude. Applicative f => PWandering (Kleisli f ) where
140- pwander (Kleisli f) = Kleisli (Prelude. traverse f)
136+ -- instance Control.Functor (Const (Top, a)) where
137+ -- fmap f (Const (t, x)) = Const (throw f <> t, x)
138+ -- instance Monoid a => Control.Applicative (Const (Top, a)) where
139+ -- pure x = Const (throw x, mempty)
140+ -- Const x <*> Const y = Const (x <> y)
141141
142142-- TODO: pick a more sensible name for this
143143newtype MyFunctor a b t = MyFunctor (b ->. (a , t ))
0 commit comments