Fix Traversing default implementation

This commit is contained in:
Kiana Sheibani 2023-03-14 12:52:45 -04:00
parent 3f6936b5b1
commit 38970b9cd5
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 12 additions and 2 deletions

View file

@ -9,6 +9,11 @@ import Data.Profunctor
%default total %default total
------------------------------------------------------------------------------
-- Default implementation machinery
------------------------------------------------------------------------------
[FoldablePair] Foldable (Pair c) where [FoldablePair] Foldable (Pair c) where
foldr op init (_, x) = x `op` init foldr op init (_, x) = x `op` init
foldl op init (_, x) = init `op` x foldl op init (_, x) = init `op` x
@ -61,6 +66,11 @@ Foldable (Baz t b) where
Traversable (Baz t b) where Traversable (Baz t b) where
traverse f bz = map (\m => MkBaz (runBazaar m)) $ runBaz bz @{Compose} $ \x => sell <$> f x traverse f bz = map (\m => MkBaz (runBazaar m)) $ runBaz bz @{Compose} $ \x => sell <$> f x
export
wanderDef : Profunctor p => (forall f. Traversable f => p a b -> p (f a) (f b))
-> (forall f. Applicative f => (a -> f b) -> s -> f t) -> p a b -> p s t
wanderDef tr f = dimap (\s => MkBaz $ \afb => f afb s) sold . tr
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Traversing interface -- Traversing interface
@ -82,7 +92,7 @@ interface (Strong p, Choice p) => Traversing p where
traverse' = wander traverse traverse' = wander traverse
wander : (forall f. Applicative f => (a -> f b) -> s -> f t) -> p a b -> p s t wander : (forall f. Applicative f => (a -> f b) -> s -> f t) -> p a b -> p s t
wander f = dimap (\s => MkBaz $ \afb => f afb s) sold . traverse' wander = wanderDef traverse'
------------------------------------------------------------------------------ ------------------------------------------------------------------------------

View file

@ -1,5 +1,5 @@
package profunctors package profunctors
version = 1.1.0 version = 1.1.1
authors = "Kiana Sheibani" authors = "Kiana Sheibani"
license = "MIT" license = "MIT"