Proposal: add Bounded instances for Maybe and Either

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue May 8 05:06:05 UTC 2018


On 8 May 2018 at 13:19, David Feuer <david.feuer at gmail.com> wrote:
> We can write
>
> instance Bounded a => Bounded (Maybe a) where
>   minBound = Nothing
>   maxBound = Just maxBound
>
> instance (Bounded a, Bounded b) => Bounded (Either a b) where
>   minBound = Left minBound
>   maxBound = Right maxBound
>
> While Bounded intentionally does not have an Ord superclass, I think it's
> worth mentioning that these are the instances that arise naturally from the
> Ord instances for the types in question.

Except these may be surprising to people; e.g. someone may expect that
`minBound = Right minBound` as well.  Though as Maybe and Either don't
have Enum instances this may be less of an issue.

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Libraries mailing list