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.

It has been a great journey learning about functional programming in Haskell. To bad I’m going to be out of the country (no internet) for the last lecture

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"

2) Express the comprehension [f x | x <- xs, p x] using the functions map and filter.

mapfilter :: (a -> b) -> (a -> Bool) -> [a] -> [b] mapfilter f p = map f . filter p

3) Redefine map f and filter p using foldr.

map' :: (a -> b) -> [a] -> [b] map' f = foldr (\x v -> f x:v) [] filter' :: (a -> Bool) -> [a] -> [a] filter' p = foldr (\x v -> if p x then x:v else v) []

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,[])

## Comments

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 13 of 13

Erik,

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.

Here is the link: http://www.amazon.com/gp/product/0394534913/ref=oss_product

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 12 of 13

While these lectures are coming to an end we can all look forward to the C9 letures on F#. Charles any idea when that's comming?

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 12 of 13

It has been a great journey learning about functional programming in Haskell. To bad I’m going to be out of the country (no internet) for the last lecture

## C9 Lectures: Dr. Graham Hutton - Functional Programming Fundamentals Chapter 11 of 13

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.

## C9 Lectures: Dr. Brian Beckman - Covariance and Contravariance in Physics 1 of 1

Thanks for this wonderful lecture.

As a side effect , the lecture and the paper gave me a good enough refresher on derivatives that I was able to solve project Euler’s problem 262. http://projecteuler.net/index.php?section=problems&id=262

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 10 of 13

These lectures have been the highlight of my Thursdays. . Thanks for taking the time to produce them. I’m looking forward to see this lecture tonight.

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 8 of 13

homework:

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)

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 7 of 13

homework:

2) Express the comprehension [f x | x <- xs, p x] using the functions map and filter.

3) Redefine map f and filter p using foldr.

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 8 of 13

Excelent lecture as always. Keep up the good work.

In the book Hutton didn't explain why he chose List instead of the Maybe type. I'm glad you touch that subject in the lecture.

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 7 of 13

Nice post Tom.

So much to learn.

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 7 of 13

Again nice lecture!

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

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 6 of 13

Here is my take on the homework:

1.- Define:

and :

concat:

replicate:

Select the Nth statement of a list:

elem:

2. Define merge :: [Int] -> [Int] -> [Int]

3. Define merge sort:

I'm having a blast with this series.