fimad / scalpel

A high level web scraping library for Haskell.
Apache License 2.0
323 stars 43 forks source link

Consider changing the type of scrape, html, and related functions #24

Closed rpglover64 closed 8 years ago

rpglover64 commented 8 years ago

scrape :: _ => Scraper str a -> [Tag str] -> Maybe a (and friends) lead to the awkward situation of scrape (htmls Any) :: [Tag str] -> Maybe [a], which IIUC will never return Just [].

Changing the type of e.g. html to _ => Scraper str (Maybe str) also has the benefit that patterns like maybe "default" <$> html become possible, leading to a richer monadic EDSL.

rpglover64 commented 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 <|>

fimad commented 8 years ago

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.

rpglover64 commented 8 years ago

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.