idris-lang / Idris2

A purely functional programming language with first class types
https://idris-lang.org/
Other
2.53k stars 380 forks source link

dont execute effect in toMaybeT if condition is not met #3274

Closed joelberkeley closed 7 months ago

joelberkeley commented 7 months ago

Description

I'm not sure about this, but is it a bug that

toMaybeT : Functor m => Bool -> m a -> MaybeT m a
toMaybeT b m = MkMaybeT $ map (\a => toMaybe b a) m

always executes its m effect.

If so, this fixes that.

See also

toMaybe : Bool -> Lazy a -> Maybe a
toMaybe True  j = Just j
toMaybe False _ = Nothing

Should this change go in the CHANGELOG?

joelberkeley commented 7 months ago

I think it was right before, but I'll change the docstring to explain why