Haskell is a popular functional programming language known for its concise syntax and powerful abstractions. Learning its basics, like syntax, structure, and tools like GHC and Cabal, is essential for efficient programming.
1. Overview of Functional Programming
What is a key characteristic of functional programming? a) Mutable state b) Use of loops c) Immutability of data d) Object-oriented principles
Which paradigm does Haskell primarily follow? a) Procedural b) Functional c) Object-Oriented d) Logic
What does “pure function” mean in Haskell? a) A function without arguments b) A function without side effects c) A function with a return value d) A function defined inside another
In functional programming, functions are treated as: a) Variables b) First-class citizens c) Immutable structures d) Objects
Which feature of functional programming ensures lazy evaluation in Haskell? a) Currying b) Referential transparency c) Lambda calculus d) Lazy loading
What is the primary benefit of immutability in functional programming? a) Increased performance b) Simplified debugging and testing c) Reduced code length d) Automatic garbage collection
Functional programming emphasizes: a) Statements and control flow b) Objects and inheritance c) Expressions and declarations d) Procedural steps
Which concept is NOT commonly associated with functional programming? a) Higher-order functions b) Recursion c) Classes and inheritance d) Pure functions
In Haskell, functions that return new values without altering inputs are called: a) Impure functions b) Recursive functions c) Pure functions d) Lazy functions
What mathematical foundation is functional programming based on? a) Lambda calculus b) Boolean algebra c) Set theory d) Graph theory
2. Installing Haskell (GHC, Stack, Cabal)
What is GHC in Haskell? a) A library for Haskell programs b) Haskell’s runtime environment c) Haskell’s compiler d) Haskell’s debugger
Which tool is used for dependency management in Haskell? a) GHC b) Cabal c) Stack d) Both b and c
What command installs Haskell using Stack? a) stack setup b) ghc install c) cabal init d) haskell setup
What is the purpose of Cabal in Haskell? a) Code debugging b) Creating and managing Haskell packages c) Running Haskell code d) Formatting Haskell programs
Which command is used to compile a Haskell program with GHC? a) ghc build b) ghc compile c) ghc filename.hs d) stack build
What is the main difference between Cabal and Stack? a) Cabal is newer, while Stack is older b) Stack provides version isolation, while Cabal doesn’t c) Cabal manages libraries, while Stack doesn’t d) Stack is faster than Cabal
How do you verify the installed version of GHC? a) ghc -v b) ghc --version c) ghc info d) ghc setup
Which command initializes a new Haskell project using Stack? a) stack init b) stack new project-name c) stack create project d) stack start
What does stack ghci do? a) Opens a REPL environment b) Compiles the Haskell project c) Installs Haskell dependencies d) Runs a Haskell script
Which tool automatically resolves library dependencies in Haskell? a) GHC b) Stack c) Cabal d) Both b and c
3. Writing and Running Basic Haskell Programs
What is the file extension for Haskell source files? a) .hs b) .hsk c) .hl d) .haskell
How do you print “Hello, World!” in Haskell? a) println "Hello, World!" b) echo "Hello, World!" c) print "Hello, World!" d) putStrLn "Hello, World!"
What does the main function represent in Haskell? a) Entry point of the program b) A helper function c) A reserved keyword d) A library function
Which of the following runs a Haskell script directly? a) runhaskell filename.hs b) haskell filename.hs c) ghci filename.hs d) compile filename.hs
What happens when you execute ghci without arguments? a) Compiles the program b) Opens an interactive REPL c) Exits with an error d) Installs missing packages
How do you declare a function in Haskell? a) function name args = expression b) def name args: expression c) name args = expression d) func name args = expression
What is a module in Haskell? a) A precompiled library b) A namespace for grouping related functions c) A set of data types d) A compiler directive
How do you import a module in Haskell? a) import module-name b) include module-name c) load module-name d) require module-name
What is the result of print (2 + 3) in Haskell? a) 2 + 3 b) 5 c) An error message d) Nothing
Which function is used to read input in Haskell? a) input b) getLine c) readLn d) readInput
Answer Key
Qno
Answer
1
c) Immutability of data
2
b) Functional
3
b) A function without side effects
4
b) First-class citizens
5
d) Lazy loading
6
b) Simplified debugging and testing
7
c) Expressions and declarations
8
c) Classes and inheritance
9
c) Pure functions
10
a) Lambda calculus
11
c) Haskell’s compiler
12
d) Both b and c
13
a) stack setup
14
b) Creating and managing Haskell packages
15
c) ghc filename.hs
16
b) Stack provides version isolation, while Cabal doesn’t