[Haskell-cafe] Missing common function for Maybe types
tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Tue Jul 31 10:24:18 UTC 2018
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.
More information about the Haskell-Cafe