module GettingStarted where import Data.List import Data.Char gen :: Int -> String gen 0 = "Sentences can go on" gen n = gen (n-1) ++ " and on" genS :: Int -> String genS n = gen n ++ "." sentences = "Sentences can go " ++ onAndOn onAndOn = "on and " ++ onAndOn sqr :: Int -> Int sqr = \ x -> x * x aword :: [Char] -> Bool aword [] = False aword (x:xs) = (x == 'a') || (aword xs) reversal :: [a] -> [a] reversal [] = [] reversal (x:t) = reversal t ++ [x] someEvens = [ x | x <- [1..1000], even x ] evensUntil n = [ x | x <- [1..n], even x ] allEvens = [ x | x <- [1..], even x ] sonnet73 = "That time of year thou mayst in me behold\n" ++ "When yellow leaves, or none, or few, do hang\n" ++ "Upon those boughs which shake against the cold,\n" ++ "Bare ruin'd choirs, where late the sweet birds sang.\n" ++ "In me thou seest the twilight of such day\n" ++ "As after sunset fadeth in the west,\n" ++ "Which by and by black night doth take away,\n" ++ "Death's second self, that seals up all in rest.\n" ++ "In me thou see'st the glowing of such fire\n" ++ "That on the ashes of his youth doth lie,\n" ++ "As the death-bed whereon it must expire\n" ++ "Consumed with that which it was nourish'd by.\n" ++ "This thou perceivest, which makes thy love more strong,\n" ++ "To love that well which thou must leave ere long." count :: Eq a => a -> [a] -> Int count x [] = 0 count x (y:ys) | x == y = succ (count x ys) | otherwise = count x ys average :: [Int] -> Rational average [] = error "empty list" average xs = toRational (sum xs) / toRational (length xs)