f (f 1 2) (f 3 4) => f (2*1+3) (f 3 4) => f 5 (f 3 4) => f 5 (2*3 + 3) => f 5 9 => 2*5 + 3=>13
- Write a function isLetter :: Char -> Bool that determines whether its argument is a letter of the alphabet.
- isletter x = (x>='A' && x<= 'Z') || (x>='a' && x<= 'z')
- Write a function capitalise :: String -> String that makes all the letters upper case.
capitalise xs = map toUpper xs
- Write a function that determines whether or not one string is the prefix of another string.
prefix [] ys = True
prefix xs [] = False
prefix (x:xs) (y:ys) = if (x==y) then prefix xs ys else False
or
prefix xs ys = (xs == take (length xs) ys)
- Write a function that occurs :: Int -> [Int] -> Int that returns the number of times a given number occurs in a list.
occurs x xs = sum [1|y<-xs, y == x]
- Write a function reverse that reverses a string.
reverse1 [] = []
reverse1 (x:xs) = (reverse1 xs) ++ [x]
or
reverse2 [] = []
reverse2 xs = rev (xs,[])
where
rev ([],ys) = ys
rev (x:xs,ys) = rev (xs, (x:ys))
- Write a function palindrome :: String -> Bool that determines whether its argument is a palindrome. A palindrome is a string which is the same when you reverse it; for example, ‘abccba’ is a palindrome, but ‘abcca’ is not.