haskellari / these

An either-or-both data type, with corresponding hybrid error/writer monad transformer.
117 stars 49 forks source link

A seemingly illegal reference to `join` in the laws #73

Closed deepfire closed 5 years ago

deepfire commented 7 years ago

Control.Monad.join (I take it..) is mentioned in the laws required of Align instances:

It seems illegal, since Monad isn't required for Align, and so the semantics are unclear.

(..to say nothing of the Bifunctor law..)

phadej commented 7 years ago
Prelude Data.These Data.Align Control.Monad> :t join align
join align :: Align f => f b -> f (These b b)
Prelude Data.These Data.Align Control.Monad> :t fmap (join These)
fmap (join These) :: Functor f => f a -> f (These a a)

join is used there for (->) a monad.

Prelude Data.These Data.Align Control.Monad> :t join :: (a -> a -> x) -> a -> x
join :: (a -> a -> x) -> a -> x :: (a -> a -> x) -> a -> x

I agree, using join is not the most clear way to stay that law, but it way more concise than alternatives. bimap is over These (which is Bifunctor), not the functor we write Align instance for.

phadej commented 7 years ago

That said, if you can improve the comments, I'll more than happily accept the PR