ekmett / contravariant

Haskell 98 contravariant functors
http://hackage.haskell.org/package/contravariant
Other
73 stars 24 forks source link

Day could be a comonad #37

Closed safareli closed 5 years ago

safareli commented 6 years ago

Not sure how useful it could be, but I think Day f g is a Comonad given f and g are Comonads.

extract :: (Comonad f, Comonad g) => Day f g a -> a
extract (Day fx gy xya) = xya (extract fx) (extract gy)

duplicate :: (Comonad f, Comonad g) => Day f g a -> Day f g (Day f g a)
duplicate (Day fx gy xya) = (Day fx gy \_ _ -> (Day fx gy xya))

This seems to be lawful.

safareli commented 6 years ago

http://blog.functorial.com/posts/2016-08-08-Comonad-And-Day-Convolution.html

paf31 commented 6 years ago

I think you want _co_variant Day.

ekmett commented 5 years ago

Day fx gy \_ _ -> (Day fx gy xya) <- the _'s there make me look askance at this definition.

You need to duplicate f and g separately, then you can fix this definition though, at least, as Phil notes, for covariant Day convolution.

sjoerdvisscher commented 5 years ago

There is a comonad instance already: https://hackage.haskell.org/package/kan-extensions-5.2/docs/src/Data.Functor.Day.html#line-103