3 ms·
> The function `a -> Maybe a` is a different function than `a -> a`. Despite his intuition that the latter provides a stronger guarantee and shouldn't break cod
by ajss 8y ago
> The function `a -> Maybe a` is a different function than `a -> a`. Despite his intuition that the latter provides a stronger guarantee and shouldn't break code, callers may be expecting the Functor instance that the `Maybe` provides and therefore is a breaking change.
I don't really follow that. How can it be a breaking change? Can you give an example?
- agentultra 8y agoIf you're building a parser, you may use: http://hackage.haskell.org/package/parsec-3.1.13.0/docs/Text-Parsec-Combinator.html#v:optionMaybe http://hackage.haskell.org/package/parsec-3.1.13.0/docs/Text... Where your downstream parsers match on `Nothing` and assume the stream hasn't been consumed in order to try an alternative parser or provide a default. If you change an equation to use `option` instead you have a completely different parser with different semantics. I was thinking of a case where I use your function in a combinator that depends on the Functor and Monoid instances provided by the `Maybe` type. If you change your function to return only the `a` and it doesn't provide those instances then you've changed the contract and have broken my code. And I suspect it should be easy to prove the equations are not equivalent.