← back

Finger exercises for Haskell

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.

  1. (from 1HaskellADay)

    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.

  4. Given the List datatype and foldr on cons-lists,

    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