Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Introduction to Haskell ====== ===== Functions in Haskell ===== In mathematics, functions have a domain an codomain. In Haskell, functions have **types** or **signatures**. They often can be omitted in Haskell, but can also be explicitly written as in: <code haskell> f :: Integer -> Integer -> Integer f x y = x + y </code> or: <code haskell> f :: Bool -> Bool f True = False f False = True </code> 3. Write a function together with its signature, which implements boolean AND: <code haskell> myand :: Bool -> Bool -> Bool ... </code> 5. Write an implementation for a function ''ifp'' which takes a boolean, expressions $math[e_1] and $math[e_2] and returns $math[e_1] if the boolean is true and $math[e_2] otherwise. <code haskell> ifp = ... </code> 6. Write a function which takes three integers and returns the largest. Hint - sometimes parentheses are **important in function calls**. <code haskell> f :: Integer -> Integer -> Integer -> Integer </code> <<We have to explain the syntax of if>> <<Explain syntax of guards>> x. Solve the previous exercise using guards <<Explain lists, head, tail>> x. Implement reversal 13. Write a function which extracts the third to last number from a list and returns ''True'', if that number is odd (hint: the function ''mod'' may be useful) <code> V f [3,4,5,2,3,9] = False f [3,4,2,1,4,4] = True </code> <<Explain pattern matching>> x. Implement the previous exercise using patterns 14. Implement a function which returns the sum of integers from a list. 15. Implement a function which takes a list of booleans and returns false if **at least** one boolean from the list is false. 16. Implement a function which filters out all odd numbers from a list. 17. Implement a function which takes a list of booleans and returns a list of integers. In the latter, (''True'' becomes ''1'' and ''False'' becomes ''0''). Example: ''f [False, True, False] = [0,1,0]''. <<Explain char and strings>> x. Write a function which removes all empty strings from a list. x. Write a function which removes all strings of size smaller than 3. Do **not** use the builtin function ''length''. x. Write a function which removes all strings having the third letter equal to 'a'. x. Write a function which: * removes all strings which are not **names**. A **name** always starts with an uppercase. * removes the last name from the resulting list of names. A name always comprises of the first name followed by the last name.