It would be great if you can mention all the other books that you recomended during the series. To Mock a Mockingbird was an excelent sugestion. Specially seeing how combinator that seem so abstract in the book can be used for equational reasoning. Thank
for that suggestion.
Just when I thought that this series couldn’t get better. Thanks Erick and Charles for putting so much effort into these lectures. Also, thanks to Dr. Hutton for taking the time to enlighten all of us.
2) Extend the parser for arithmetic expressions to support substraction and division, based upon the following extensions to the grammar:
expr ::= term (+ expr | - expr | e) term ::= factor (* term | / term | e)
expr' :: Parser Int expr' = do t <- term' do symbol "+" e <- expr' return (t + e) +++ do symbol "-" e <- expr' return (t - e) +++ return t term' :: Parser Int term' = do f <- factor' do symbol "*" t <- term' return (f * t) +++ do symbol
"/" e <- expr' return (f `div` e) +++ return f factor' :: Parser Int factor' = do symbol "(" e <- expr' symbol ")" return e +++ natural eval' :: String -> Int eval' xs = case parse expr' xs of [(n,)] -> n [(_,out)] -> error ("unused input " ++ out)  ->
error "invalid input"
A comment about implementing takeWhile and dropWhile using foldr. These are functions to take or drop elements at the beginning of a list. So, I think it would be easier to implement them using foldl (fold left). Can it be done with foldr? I’m not sure.
The drawback to implement them with fold is that they would be useless when dealing with infinite lists. That is because fold(r|l) consume the whole list before producing a result.
Here is my take on both using foldl
takeWhile' :: (a -> Bool) -> [a] -> [a] takeWhile' p = snd . foldl (\(e,v) x -> if e then (e,v) else if p x then (False,v++[x]) else (True,v)) (False,) dropWhile' :: (a -> Bool) -> [a] -> [a] dropWhile' p = snd . foldl (\(e,v) x -> if
e then (e,v++[x]) else if p x then (True,v) else (False,v++)) (False,)