[Haskell-cafe] Missing common function for Maybe types
marc at lamarciana.com
Tue Jul 31 12:07:38 UTC 2018
On Tue, 31 Jul 2018, Tom Ellis wrote:
> On Tue, Jul 31, 2018 at 09:47:07AM +0200, Marc Busqué wrote:
>> Apologies, I clearly asked the question in a rushed way...
>> I'm working with [req](http://hackage.haskell.org/package/req) package.
>> I need to parse a url from a string, but I don't know whether its schema
>> will be `http` or `https`. However, `req` just provides me with two
>> parseUrlHttp :: ByteString -> Maybe (Url Http, Option scheme)
>> parseUrlHttps :: ByteString -> Maybe (Url Https, Option scheme)
> This just sounds like bad API design from req. Why is the API not
> parseUrl :: ByteString -> Maybe (Either (Url Http) (Url Https), Option scheme)
>> What I think is a common case here (perhaps I'm wrong) is the need to
>> choose between two or more `Maybe` values where at most one of them will
>> be a `Just`.
> If that invariant really does hold then the authors of those functions
> should encode the invariant in the type. Requiring clients to observe the
> invariant for themselves sounds like a bad idea.
It sounds reasonably. I have opened an [issue in
req](https://github.com/mrkkrp/req/issues/48) with this feature request.
More information about the Haskell-Cafe