Function Implementation
Write Haskell functions using higher-order functions, list comprehensions, and functional programming techniques without explicit recursion.
17 questions
Zip and Concatenate String Lists
A function f2 :: ([String], [String]) -> [String] that zips two string lists together, concatenating each pair.
Repeat Characters by Position
A function f3 :: String -> String that repeats each character n times, where n is its position in the string (starting at 1).
Count Positive Numbers Divisible by 3
A function f4 :: [Int] -> Int that returns the number of positive numbers divisible by 3.
Product of Integer Pairs
A function f5 :: [(Int, Int)] -> [Int] that takes a list of Int-pairs and returns a list of their products.
Infinite Powers of 2 (Corrected)
Create an infinite list of powers of 2: [1,2,4,8,16,..]
Partial Sums using scanl (Corrected)
Define a function partialSums :: Num a => [a] -> [a] that returns a list of partial sums using scanl.
Interleave Infinite Lists (Corrected)
Define a function interleave :: [a] → [a] → [a] that lazily interleaves two infinite lists.
Alternating String Letters
A function f :: (String, String) -> String generating a String from two arguments by alternating letters from each argument.
First Characters of Non-Empty Strings
A function f1 :: [String] -> [Char] that returns the first character of each non-empty string in a list.
Remove Vowels from String
A function f2 :: String -> String that removes all vowels from a string.
Count True Values
A function f3 :: [Bool] -> Int that counts how many True values are in a list.
Fibonacci Numbers with Scanl
Define a function fibs :: [Integer] that returns the infinite list of Fibonacci numbers using scanl.
Powers of Number with Iterate
Define a function powersOf :: Integer -> [Integer] that returns an infinite list of powers of a given number using iterate.
Zip and Concatenate String Lists (Fixed)
A function f2 :: ([String], [String]) -> [String] that zips two string lists together, concatenating each pair.
Repeat Characters by Position (Fixed)
A function f3 :: String -> String that repeats each character n times, where n is its position in the string (starting at 1).
Count Positive Numbers Divisible by 3 (Corrected)
A function f4 :: [Int] -> Int that returns the number of positive numbers divisible by 3.
Product of Integer Pairs (Corrected)
A function f5 :: [(Int, Int)] -> [Int] that takes a list of Int-pairs and returns a list of their products.
Type Inference
Determine the most general types of Haskell expressions, paying attention to type classes and polymorphism.
24 questions
Empty Lists Type
What is the most general type of: [ [], [] ]
Lambda with Bool Application
What is the most general type of: \x y -> (x False, y)
Mixed Tuple Type
What is the most general type of: ([], [False])
List Constructor Expression
What is the most general type of: [] : []
Map with Bool List
What is the most general type of: \f -> map f [True]
Empty List Function
What is the most general type of: \[] -> []
Conditional Bool List
What is the most general type of: \x -> if x then [] else [x]
Addition Lambda
What is the most general type of: \(x, y) -> x + y
Equality Test Lambda
What is the most general type of: \x -> x == x
Map Application Lambda
What is the most general type of: \x y -> map x y
Empty Tuple Pair
What is the most general type of: ([], [])
Mixed Triple
What is the most general type of: ([], [], [1])
Bool Tuple List
What is the most general type of: (False, 99):[]
Numeric Addition Lambda
What is the most general type of: \x y -> (x y) + 7
Function Application List
What is the most general type of: \x y -> [x y]
Head Function Application
What is the most general type of: \x -> head (x 9)
List Constructor Lambda
What is the most general type of: \x y -> x : y
Function Tuple Application
What is the most general type of: \x -> (x, x 4)
ZipWith Application
What is the most general type of: \x y -> zipWith x y y
List Duplication
What is the most general type of: \x -> [x, x]
Tuple Duplication
What is the most general type of: \x -> (x, x)
Function Application to 5
What is the most general type of: \x -> (x 5)
List Pair
What is the most general type of: \x y -> [x, y]
Numeric Pair Operations
What is the most general type of: \x -> \y -> (x + y, x * y)
Type Construction
Construct expressions that match given type signatures, demonstrating understanding of Haskell's type system.
17 questions
Triple Bool Function
Create an expression with type: Bool -> Bool -> Bool -> [Bool]
Numeric Triple Function
Create an expression with type: Num a => a -> a -> a -> a
Pair List Function
Create an expression with type: a -> [(a,a)]
Mixed Numeric Tuple
Create an expression with type: Num a, Fractional b => a -> b -> Bool -> (a, b, Bool)
Function Application Pair
Create an expression with type: (a -> b) -> a -> (a, b)
Equality Function
Create an expression with type: Eq a => a -> a -> Bool
Maximum from List
Create an expression with type: Ord a => [a] -> a
List Predicate Function
Create an expression with type: [a] -> (a -> Bool) -> Bool
Fractional Average
Create an expression with type: Fractional a => a -> a -> a
Function Composition
Create an expression with type: (a -> b) -> (b -> c) -> a -> c
IO Bool Expression
Create an expression with type: IO Bool
Show to IO Expression
Create an expression with type: Show a => a -> IO ()
List Map Expression
Create an expression with type: [a] -> (a -> b) -> [b]
Complex Constraint Expression
Create an expression with type: (Fractional a, Eq b, Num b) => (a -> b) -> b -> Bool
Curried Addition Expression
Create an expression with type: Num a => a -> (a -> a)
Function Pair Application
Create an expression with type: (a -> b, a) -> b
Boolean Logic Expression
Create an expression with type: Bool -> (Bool -> Bool) -> Bool
Multiple Choice
Test your knowledge of Haskell concepts, syntax, and functional programming principles through multiple choice questions.
8 questions
Map and Filter Expression
What does the following expression return?
Lambda Expression Rewrite
Which of the following rewrites map f xs using a lambda expression?
Foldr vs Foldl Difference
Which of the following best describes the difference between foldr and foldl in Haskell?
Function Composition for Even Squares
How would you use function composition to define a function that squares all even numbers in a list?
Lazy Evaluation and Infinite Lists
Why does length [1..] never terminate, while take 10 [1..] does?
Type of putChar
What is the type of putChar?
IO () vs IO String Difference
What is the difference between IO () and IO String?
Return Function in Haskell
What does return do in Haskell?
Short Answer
Evaluate Haskell expressions and explain concepts with concise answers, covering language fundamentals and computation.
22 questions
Type Classes Definition
What is a type class in Haskell?
Eq Class Requirements
What must a type implement to be an instance of the Eq class?
Bind Operator Function
What does the >>= operator do?
File Writing in Haskell
How can you write to a file in Haskell?
Let Expression Evaluation
What is the result of: let x = 1 in let x = 2 in x + x
List Comprehension with Take
What is the result of: take 5 [x*(x+1) | x <- [1..]]
Foldl Subtraction
What is the result of: foldl (\acc x -> acc - x) 10 [1,2,3]
Function Composition with Head and Reverse
What is the result of: (head . reverse) [10,20,30,40]
ZipWith Addition
What is the result of: zipWith (+) [1,2,3] [4,5]
All Even Predicate
What is the result of: all even [2,4,6,8]
List Comprehension with Guards
What is the result of: [ (x, y) | x <- [1,2], y <- [1,2], x /= y]
ZipWith String Concatenation
What is the result of: zipWith (++) ["a", "b", "c"] ["1", "2"]
Take with Iterate
What is the result of: take 3 (iterate (*2) 1)
Function Composition with Not and All
What is the result of: (not . all even) [2,4,6,7]
Foldr Subtraction Result
What is the result of: foldr (-) 0 [10,8,6,4,2]
Map with Let Binding
What is the result of: let f x = x * 2 in map f [1,2,3]
Nested Let Expression
What is the result of: let x = 3 in x + (let x = 2 in x * x)
Map Filter Chain
What is the result of: map (*2) (filter (>3) [1..6])
List Comprehension with Guards
What is the result of: [x | x <- [10,9..1], even x, x `mod` 3 /= 0]
Foldl String Accumulation
What is the result of: foldl (\acc x -> acc ++ show x) "" [1,2,3]
Head of Squares Comprehension
What is the result of: head [x^2 | x <- [1..], x^2 > 100]
Map Filter Even Expression
What does the following expression return: map (*2) (filter even [1..10])
Io Program
Write complete Haskell programs that perform input/output operations using the IO monad and file operations.
6 questions
Name Greeting Program
Implement an executable Haskell program that asks the user for their name, then greets them and prints the number of characters in their name.
Word Count Program
Implement an executable Haskell program that reads a file "text.txt" and prints how many words it contains.
Filter Non-Empty Lines
Implement an executable Haskell program that reads a file "notes.txt" and copies only non-empty lines to the file "clean_notes.txt".
Reverse Name Program
Implement an executable Haskell program reading a name from console and printing it backwards.
Loop Until Stop Program
Implement an executable Haskell program that keeps on reading lines until the user types "stop". After that, print "Done!".
Uppercase Names File Processing
The file "names.txt" contains one name per line. Implement an executable Haskell program that reads the file, converts all names to uppercase and writes the result to the file "NAMES.txt".
Concept Explanation
Explain key functional programming and Haskell concepts in your own words, demonstrating deep understanding.
2 questions
Type Class Functions
Describe the following type classes and give an example function for each: Num, Ord, Show, Enum, Bounded
Extended Type Class Functions
Describe the following type classes and give an example function for each: Num, Ord, Show, Enum, Bounded