bifunctor

Type Signature Mismatch on Bifunctor instance definition

穿精又带淫゛_ 提交于 2020-01-24 07:24:11
问题 I'm learning about Haskell by working through the book Haskell Programming from First Principles, Allen & Moronuki. In the exercises for the chapter on Monad Transformers, Functor & Applicative composition, it asks the reader to write Bifunctor instance for the following type data SemiDrei a b c = SemiDrei a My first attempt (which compiles) was instance Bifunctor (SemiDrei a) where bimap f g (SemiDrei a) = SemiDrei a But, looking at it, It seemed to me that I ought to be able to write bimap

What would be the methods of a bi-comonad?

不羁的心 提交于 2019-12-05 16:08:56
问题 While musing what more useful standard class to suggest to this one class Coordinate c where createCoordinate :: x -> y -> c x y getFirst :: c x y -> x getSecond :: c x y -> y addCoordinates :: (Num x, Num y) => c x y -> c x y -> c x y it occured me that instead of something VectorSpace-y or R2, a rather more general beast might lurk here: a Type -> Type -> Type whose two contained types can both be extracted. Hm, perhaps they can be extracted ? Turns out neither the comonad nor bifunctors

Traversing with a Biapplicative

a 夏天 提交于 2019-12-05 10:28:22
问题 I was thinking about unzipping operations and realized that one way to express them is by traversing in a Biapplicative functor. import Data.Biapplicative class Traversable2 t where traverse2 :: Biapplicative p => (a -> p b c) -> t a -> p (t b) (t c) -- Note: sequence2 :: [(a,b)] -> ([a], [b]) sequence2 :: (Traversable2 t, Biapplicative p) => t (p b c) -> p (t b) (t c) sequence2 = traverse2 id instance Traversable2 [] where traverse2 _ [] = bipure [] [] traverse2 f (x : xs) = bimap (:) (:) (f

What would be the methods of a bi-comonad?

a 夏天 提交于 2019-12-04 01:26:57
While musing what more useful standard class to suggest to this one class Coordinate c where createCoordinate :: x -> y -> c x y getFirst :: c x y -> x getSecond :: c x y -> y addCoordinates :: (Num x, Num y) => c x y -> c x y -> c x y it occured me that instead of something VectorSpace -y or R2 , a rather more general beast might lurk here: a Type -> Type -> Type whose two contained types can both be extracted. Hm, perhaps they can be extract ed ? Turns out neither the comonad nor bifunctors package contains something called Bicomonad . Question is, would such a class even make sense,

Traversing with a Biapplicative

China☆狼群 提交于 2019-12-03 22:37:28
I was thinking about unzipping operations and realized that one way to express them is by traversing in a Biapplicative functor. import Data.Biapplicative class Traversable2 t where traverse2 :: Biapplicative p => (a -> p b c) -> t a -> p (t b) (t c) -- Note: sequence2 :: [(a,b)] -> ([a], [b]) sequence2 :: (Traversable2 t, Biapplicative p) => t (p b c) -> p (t b) (t c) sequence2 = traverse2 id instance Traversable2 [] where traverse2 _ [] = bipure [] [] traverse2 f (x : xs) = bimap (:) (:) (f x) <<*>> traverse2 f xs It smells to me as though every instance of Traversable can be transformed