Note: Anonymous functions are not introduced until chapter 9! But they are an easy way to solve problems like this.

mylength :: [a] -> Int mylength xs = foldl (\x _ -> x + 1) 0 xs |

solutions from the exercises in the book

Note: Anonymous functions are not introduced until chapter 9! But they are an easy way to solve problems like this.

mylength :: [a] -> Int mylength xs = foldl (\x _ -> x + 1) 0 xs |

same one without anonymous function

length1 x = foldl count 0 x where count x y = x + 1