MCQs on Introduction to Haskell | Haskell

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

  1. What is a key characteristic of functional programming?
    a) Mutable state
    b) Use of loops
    c) Immutability of data
    d) Object-oriented principles
  2. Which paradigm does Haskell primarily follow?
    a) Procedural
    b) Functional
    c) Object-Oriented
    d) Logic
  3. 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
  4. In functional programming, functions are treated as:
    a) Variables
    b) First-class citizens
    c) Immutable structures
    d) Objects
  5. Which feature of functional programming ensures lazy evaluation in Haskell?
    a) Currying
    b) Referential transparency
    c) Lambda calculus
    d) Lazy loading
  6. 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
  7. Functional programming emphasizes:
    a) Statements and control flow
    b) Objects and inheritance
    c) Expressions and declarations
    d) Procedural steps
  8. Which concept is NOT commonly associated with functional programming?
    a) Higher-order functions
    b) Recursion
    c) Classes and inheritance
    d) Pure functions
  9. In Haskell, functions that return new values without altering inputs are called:
    a) Impure functions
    b) Recursive functions
    c) Pure functions
    d) Lazy functions
  10. 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)

  1. What is GHC in Haskell?
    a) A library for Haskell programs
    b) Haskell’s runtime environment
    c) Haskell’s compiler
    d) Haskell’s debugger
  2. Which tool is used for dependency management in Haskell?
    a) GHC
    b) Cabal
    c) Stack
    d) Both b and c
  3. What command installs Haskell using Stack?
    a) stack setup
    b) ghc install
    c) cabal init
    d) haskell setup
  4. 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
  5. Which command is used to compile a Haskell program with GHC?
    a) ghc build
    b) ghc compile
    c) ghc filename.hs
    d) stack build
  6. 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
  7. How do you verify the installed version of GHC?
    a) ghc -v
    b) ghc --version
    c) ghc info
    d) ghc setup
  8. Which command initializes a new Haskell project using Stack?
    a) stack init
    b) stack new project-name
    c) stack create project
    d) stack start
  9. What does stack ghci do?
    a) Opens a REPL environment
    b) Compiles the Haskell project
    c) Installs Haskell dependencies
    d) Runs a Haskell script
  10. 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

  1. What is the file extension for Haskell source files?
    a) .hs
    b) .hsk
    c) .hl
    d) .haskell
  2. How do you print “Hello, World!” in Haskell?
    a) println "Hello, World!"
    b) echo "Hello, World!"
    c) print "Hello, World!"
    d) putStrLn "Hello, World!"
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. How do you import a module in Haskell?
    a) import module-name
    b) include module-name
    c) load module-name
    d) require module-name
  9. What is the result of print (2 + 3) in Haskell?
    a) 2 + 3
    b) 5
    c) An error message
    d) Nothing
  10. Which function is used to read input in Haskell?
    a) input
    b) getLine
    c) readLn
    d) readInput

Answer Key

QnoAnswer
1c) Immutability of data
2b) Functional
3b) A function without side effects
4b) First-class citizens
5d) Lazy loading
6b) Simplified debugging and testing
7c) Expressions and declarations
8c) Classes and inheritance
9c) Pure functions
10a) Lambda calculus
11c) Haskell’s compiler
12d) Both b and c
13a) stack setup
14b) Creating and managing Haskell packages
15c) ghc filename.hs
16b) Stack provides version isolation, while Cabal doesn’t
17b) ghc --version
18b) stack new project-name
19a) Opens a REPL environment
20d) Both b and c
21a) .hs
22d) putStrLn "Hello, World!"
23a) Entry point of the program
24a) runhaskell filename.hs
25b) Opens an interactive REPL
26c) name args = expression
27b) A namespace for grouping related functions
28a) import module-name
29b) 5
30b) getLine

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top