# Matthew Chan

← back

1 February 2017

Here’s a selection of point-free style/program calculation exercises I came up with for cse130. Enjoy!

With thanks to @taktoa

Give solutions to the following in points-free style.

Given: parseNum :: String -> Maybe (Float, String)

Define: dropNum :: String -> Maybe String in terms of parseNum

2. Define a function applys :: a -> [a -> b] -> [b] that applies a value to a list of functions.

3. Define a function wordCount :: [String] -> [(String, Int)] that, given a list of words, returns an association list with the number of occurrences of each unique word.

• Define the function histogram :: FilePath -> IO () that reads a file, computes the wordCount of the contents, and draws a histogram to the screen. Assume the function printCount :: String -> Int -> IO ().
4. Given the List datatype and foldr on cons-lists, haskell data List a = Nil | Cons a (List a)

foldr :: (a -> b -> b) -> b -> List a -> b foldr f b Nil = b foldr f b (Cons x xs) = f x (foldr f b xs) 

define its counterpart foldl over snoc-lists of type Tisl

data Tisl a = Lin | Snoc (Tisl a) a

foldl :: (a -> b -> a) -> a -> Tisl b -> a
• Must the step function for foldr have the type a -> b -> b for both List and Tisl? What about the type of the step function for foldl? Give an explanation based on the structure of cons and snoc lists and the shape of the recursion.
• Prove that foldl is the natural fold for snoc-lists.

stuff