4. Defining functions Flashcards
1
Q
Function to split list at a specific index
A
splitAt :: Int -> [a] -> ([a], [a])
splitAt n xs = (take n xs, drop n xs)
2
Q
What is the syntax of a conditional expression
A
abs :: Int -> Int
abs n = if n >= 0 then n else -n
3
Q
What is the syntax of a guarded equation?
A
signum n | n < 0 = -1
| n == 0 = 0
| otherwise = 1
4
Q
Function that uses a lambda expression for getting odd numbers from 0 to n
A
odds :: Int -> [Int]
odds n = map (\x -> x * 2 + 1) [0..n-1]