Open int-index opened 3 years ago
Sounds good to me, does @phadej have an opinion? A PR would be very welcome.
I do see a benefit of having functions with S.Maybe a -> (a -> S.Maybe b) -> S.Maybe b
signature. And there is an obvious way. However I'm unsure whether it's wise to use strict Maybe
as control structure, yet it's probably handy to be able to try to swap lazy Maybe to strict Maybe, as an experiment.
A PR adding the same instances https://hackage.haskell.org/package/base-4.14.1.0/docs/Data-Maybe.html#t:Maybe has is fine. As long as there is disclaimer which would allow us to close issues re. bottoms with "you have been warned".
TL;DR I'm quite sure there would be issues like "I swapped lazy maybe to strict maybe, and my program started to crash instead of running faster".
That would only affect new users that attempt to take advantage of this feature, though - it doesn't cause any backwards-compat issues as the instance doesn't exist currently so nobody would be using it.
Yes, I it won't break any existing code. I didn't mean that.
Let us wait for a patch. I'd expect an instances come with a documentation of their partial lawfulness.
I'm confused by this because there is a Functor
instance, but I don't believe Data.Strict.Maybe
is technically a Functor
:
> let f = const ()
> let g = const undefined
> fmap (f . g) (Data.Strict.Just ())
Just ()
> (fmap f . fmap g) (Data.Strict.Just ())
*** Exception: Prelude.undefined
Or did I misinterpret something?
@tomjaguarpaw we agreed to add instances. We are waiting for a patch.
In
Data.Strict.Maybe
, I see the following argument for omitting theApplicative
instance:However, I don’t think it holds water, because by the same token Haskell doesn’t even have the
State
monad, see http://www.cse.chalmers.se/~nicsma/no-state-monad.htmlInstead, I think the right thing to do is to acknowledge that type class laws typically hold only if we ignore bottom, and implement the usual
Applicative
andMonad
instances for the strictMaybe
(and other types in the library).