-- Some examples demonstrating recursion and pattern matching. -- by Scot Drysdale on 9/27/07, modified 9/25/2008 -- Computes the length of a string strLength :: [Char] -> Int strLength [] = 0 strLength (c:rest) = 1 + strLength rest -- listSum implemented recursively (from SOE) listSum :: [Double] -> Double listSum [] = 0.0 listSum (num:rest) = num + listSum rest -- Reverses a string reverseString :: [Char] -> [Char] reverseString [] = [] reverseString (x:xs) = reverseString xs ++ [x] -- A faster way to reverse a string, using a helper function reverseStringFast :: [Char] -> [Char] reverseStringFast xs = rev [] xs where rev acc [] = acc rev acc (x:xs) = rev (x:acc) xs