Here are some exercises to try before Friday. There's nothing to turn in or be graded but you'll learn more if you take the time to give these a try. Feel free to discuss these problems on Piazza and/or with me.
  1. On paper, rewrite these expressions using Haskell function call syntax:
    f(x) * a == g(a) + c
        
    h(f(a) + g(x-y))
        
    f(g(a*-b)-h(b))
    
  2. Try :info on these types/type classes: Eq, Bool, Int, Ord, Bounded. Several end in many lines of this general form: instance (Eq a, Eq b, Eq c) => Eq (a, b, c). Ignore that stuff for now. Focus on what precedes it.
  3. Try :type on the following functions and then try some calls of the functions. even, id, pred, abs, signum
  4. As shown on slide 42, use :m Data.Char to load the Data.Char module and then do :browse (no arguments) to see all the functions in the module. Try ord, chr, isPunctuation, isHexDigit, and toTitle. Regarding values for ord and chr, Google for ASCII chart.
  5. Hoogle searches Haskell documentation. Hit http://www.haskell.org/hoogle/?hoogle=toTitle (Suggestion: Set up a Chrome "Search Engine" for Hoogle. Slide 28 in http://www.cs.arizona.edu/classes/cs337/fall13/files/html.pdf has a sketchy how-to. The Firefox analog is "keywords".)
  6. Try :type pi and :type minBound. Are they functions?
  7. Try these expressions, which use :: to request that the value have a specific type.
    minBound::Char
    maxBound::Bool
    maxBound::Int
    maxBound::Integer (it's an error, but why?)
    
  8. Try the function defintions on slide 65 and then write some single-argument functions: We haven't seen if-else or guards, so define the above using only operators, which are on slide 79. Use :set +t to cause the type of each to be automatically shown.
  9. Get creative: Think up three more significantly different single-argument functions.
  10. Define functions f1 through f6 whose types are inferred to be the following. The functions don't need to perform any meaningful computation—only the type matters. You may NOT use ::type (as shown on slide 66) to force types.
    f1 :: Eq a => a -> Bool
    f2 :: Num a => t -> a
    f3 :: Fractional a => t -> a
    f4 :: Int -> Int
    f5 :: (Bounded a, Ord a) => a -> Bool
    f6 :: (Bounded a, Eq a) => a -> Bool
    
  11. Get creative: Imagine a function type and then write a function that will be inferred to have that type. Do three functions.
  12. On slide 52, I'm wondering if there should really be an arrow from Eq to Num. Use :info to explore various classes including Eq and Num and see if you can tell me why I'm doubtful on this. Don't Google!