Closed rpglover64 closed 8 years ago
I got a quick and dirty draft of it up here: https://github.com/rpglover64/scalpel/tree/no-maybe
We lose Alternative
(and MonadPlus
), due to lack of empty
; we can still define <|>
Hrmm I'm not sure I see the benefit of Maybe a
over just a
given that you can do html "foo" <|> return "default"
.
I feel like the majority of the time when I write foo <- text "bar"
I want foo to be a use-able value and not something I have to further extract.
This is the most tentative of the issues I filed; I'm not even sold on it.
I was about to say, "I think the more important thing I was missing was an interface to work over a list of values without running the monad twice," but then I realized that join
(possibly with sequence
) should be that interface.
I think you're right that the convenience of having the value you want right at your fingertips overrides the slight code smell of Maybe [a]
.
If the non-empty list package were easier to work with, I might have suggested that, but as it is, I think I can close the issue.
scrape :: _ => Scraper str a -> [Tag str] -> Maybe a
(and friends) lead to the awkward situation ofscrape (htmls Any) :: [Tag str] -> Maybe [a]
, which IIUC will never returnJust []
.Changing the type of e.g.
html
to_ => Scraper str (Maybe str)
also has the benefit that patterns likemaybe "default" <$> html
become possible, leading to a richer monadic EDSL.