Programming Language Concepts
4.0 Credits
Final Exam Review (Qns & Ans)
2025
Case Context for Questions 1-5
©2025
,Consider a new programming language, XenLang, designed with
features such as lazy evaluation, dependent types, and advanced
polymorphism. XenLang supports both eager and lazy evaluation
modes, dependent typing for enhanced type safety, and
polymorphic type inference.
1. (MCQ)
In XenLang, lazy evaluation is primarily beneficial because:
A) It increases memory consumption by creating many thunks.
B) It delays computation until the result is needed, which can
improve performance in some cases.
C) It eliminates the need for garbage collection.
D) It makes the language purely functional without side effects.
ANS: B
Rationale: Lazy evaluation defers computation until its value is
actually needed, which can avoid unnecessary calculations and
improve performance. It may increase memory use due to thunks,
but the main benefit is avoiding wasted computation.
2. (FIB)
Dependent types in XenLang allow types to depend on
__________, enabling more expressive type constraints checked at
compile time.
ANS: values
Rationale: Dependent types can depend on program values,
allowing the type system to express precise properties such as
array length or numerical invariants checked during compilation.
3. (T/F)
The polymorphic type inference in XenLang means every
polymorphic function must have explicit type annotations to be
correctly typed.
ANS: False
Rationale: Polymorphic type inference generally allows the
compiler to deduce types automatically without requiring explicit
©2025
,annotations, although annotations can improve readability or
resolve ambiguities.
4. (MR)
Which of the following features are typically associated with lazy
evaluation languages? (Select all that apply)
A) Thunks
B) Call-by-value parameter passing
C) Memoization of computed values
D) Eager infinite loop evaluation
ANS: A, C
Rationale: Thunks implement delayed computation, and
memoization avoids recomputing thunks once evaluated. Call-by-
value is eager evaluation, and eager infinite loop evaluation would
not terminate.
5. (MCQ)
Dependent types improve:
A) Run-time performance
B) Static program verification
C) Dynamic typing flexibility
D) Garbage collection optimization
ANS: B
Rationale: Dependent types mainly help prove program correctness
at compile time by encoding invariants into types, hence improving
static verification.
Case Context for Questions 6-10
You are analyzing the semantics of a concurrent programming
language called ConcurLang that supports message passing
concurrency and weak memory models.
6. (MCQ)
In ConcurLang’s weak memory model, which of the following
behaviors is allowed?
A) Reading stale values due to reordering by the hardware
©2025
, B) Sequential consistency across all threads always guaranteed
C) Atomic reads and writes to shared variables without
synchronization
D) No race conditions can occur
ANS: A
Rationale: Weak memory models permit hardware or compilers to
reorder instructions leading to visibility of stale values between
threads, unlike sequential consistency.
7. (FIB)
In the context of message passing concurrency, __________ is a
communication pattern where processes synchronize by sending
and receiving messages directly.
ANS: synchronous communication
Rationale: Synchronous message passing requires sender and
receiver to rendezvous for communication, as opposed to
asynchronous message passing.
8. (T/F)
In ConcurLang, the use of locks is unnecessary if all shared state is
encapsulated within message-passing processes.
ANS: True
Rationale: Encapsulating shared state inside message-passing
reduces the need for explicit locks by avoiding shared mutable
memory accessed concurrently.
9. (MR)
Which of the following are typical problems faced when
implementing concurrency under weak memory models? (Select
all)
A) Data races
B) Deadlocks due to improper locks
C) Memory visibility issues
D) Overflow errors in arithmetic operations
©2025