[Split chapter 3 into a new chapter 4 Bryan O'Sullivan **20070721053913] { move ./en/ch04-library.xml ./en/ch05-library.xml move ./en/ch05-typeclasses.xml ./en/ch06-typeclasses.xml move ./en/ch06-io.xml ./en/ch07-io.xml move ./en/ch07-globs-and-regexps.xml ./en/ch08-globs-and-regexps.xml adddir ./examples/ch04 hunk ./en/00book.xml 14 - - - - + + + + + hunk ./en/00book.xml 98 + &ch08; hunk ./en/ch03-funcs-types.xml 1215 - - - Example: Run-Length Encoding - FIXME: Example: run-length encoding. Use to show how - looping can be done via tail recursion. - - - - - Type Inference - FIXME: Discuss type inference: what it is and how it can - save a lot of work. - - - - - Anonymous (Lambda) Functions - FIXME - - - - Partial Application - FIXME - - - - Typeclasses - FIXME: Introduce type classes. Show how ghci infers types - with constraints. Define some functions that use type class - constraints. Talk about when it's appropriate to write explicit - signatures. - - See also . - - - - Example: Data.Map API - FIXME: Small example would be a finite map data structure - API, with a list and tree implementation (different complexity, - same api). Ties together basic types, small functions, top level - functions. class Map m where new :: m k v insert :: k -> v - -> m k v -> m k v lookup :: k -> m k v -> v -- simple, O(n) - data Map1 k v = [(k,v)] -- less simple, O(log n) data Map2 k v = - Node k v (Map2 k v) (Map2 k v) | Empty - - - addfile ./en/ch04-fp.xml hunk ./en/ch04-fp.xml 1 + + + + Functional programming + + FIXME + + + Example: Run-Length Encoding + FIXME: Example: run-length encoding. Use to show how + looping can be done via tail recursion. + + + + + Type Inference + FIXME: Discuss type inference: what it is and how it can + save a lot of work. + + + + + Anonymous (Lambda) Functions + FIXME + + + + Partial Application + FIXME + + + + Typeclasses + FIXME: Introduce type classes. Show how ghci infers types + with constraints. Define some functions that use type class + constraints. Talk about when it's appropriate to write explicit + signatures. + + See also . + + + + Example: Data.Map API + FIXME: Small example would be a finite map data structure + API, with a list and tree implementation (different complexity, + same api). Ties together basic types, small functions, top level + functions. class Map m where new :: m k v insert :: k -> v + -> m k v -> m k v lookup :: k -> m k v -> v -- simple, O(n) + data Map1 k v = [(k,v)] -- less simple, O(log n) data Map2 k v = + Node k v (Map2 k v) (Map2 k v) | Empty + + + + + + addfile ./examples/ch04/RunLength.hs hunk ./examples/ch04/RunLength.hs 1 +runLength [] = [] +runLength (x:xs) = runLength' 1 x xs + where + runLength' n a [] = [(n, a)] + runLength' n a (x:xs) + | a == x = runLength' (n+1) a xs + | otherwise = (n, a) : runLength' 1 x xs }