--- Example for a Curry program which extracts email addresses --- from a HTML page. --- Since this program requires a few libraries, it must be executed --- as follows: --- --- > cypm add -d setfunctions # add dependencies --- > cypm add -d html2 --- > cypm install # install required dependencies --- > pakcs :l EmailsInHtml :eval main :quit import Control.SetFunctions import HTML.Base import HTML.Parser -- Representation of HTML documents defined in HTML.Base as follows: -- data StaticHtml = HText String | HStruct String Attrs [StaticHtml] -- Gets some HTML document containing the argument HTML element. withHtmlElem :: StaticHtml -> StaticHtml withHtmlElem helem = helem ? HStruct _ _ (withElem (withHtmlElem helem)) -- Gets some list containing a given element. withElem :: Data a => a -> [a] withElem e = e:_ ? _:withElem e -- Extracts some email address in an HTML document. anyEmailAddress :: StaticHtml -> String anyEmailAddress (withHtmlElem (HStruct _ (withElem ("href","mailto:" ++ name)) _)) = name -- collect and print all email addresses in an HTML document: main :: IO () main = do elems <- readHtmlFile "syllabus.html" printValues (set1 anyEmailAddress (head elems))