Commit e0d8f254 authored by Mart Lubbers's avatar Mart Lubbers

add alternative default instances for bifunctor and traversable

parent 5f568e28
Pipeline #16899 passed with stage
in 2 minutes and 48 seconds
......@@ -3,6 +3,7 @@ definition module Data.Bifunctor
class Bifunctor p
where
bifmap :: (a -> b) (c -> d) (p a c) -> p b d
bifmap l r a = first l (second r a)
first :: (a -> b) (p a c) -> p b c
first l a = bifmap l (\x->x) a
second :: (b -> c) (p a b) -> p a c
......
......@@ -3,6 +3,7 @@ definition module Data.Traversable
from Control.Applicative import class pure, class <*>, class Applicative
from Control.Monad import class Monad
from Data.Functor import class Functor
import qualified Data.Functor
from Data.Foldable import class Foldable
from Data.Monoid import class Monoid, class Semigroup
......@@ -95,6 +96,7 @@ class Traversable t | Functor t & Foldable t where
// Map each element of a structure to an action, evaluate
// these actions from left to right, and collect the results.
traverse :: (a -> f b) !(t a) -> f (t b) | Applicative f
traverse f a = sequenceA ('Data.Functor'.fmap f a)
// Evaluate each action in the structure from left to right,
// and collect the results.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment