×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

F# MCQs (Multiple-Choice Questions)

Test your knowledge of F# programming with these multiple-choice questions (MCQs) and answers. These F# MCQs cover functional programming concepts, functions, variables, pattern matching, lists, arrays, sequences, records, discriminated unions, options, modules, classes, interfaces, computation expressions, and other important F# language features.

F# MCQs

F# is a functional-first programming language on the .NET platform. It supports functional, object-oriented, and imperative programming styles, with features such as type inference, pattern matching, immutable data, discriminated unions, computation expressions, and concise function definitions.

List of F# MCQs

Practice the following F# multiple-choice questions to improve your understanding of the language and prepare for technical interviews, examinations, and programming assessments.

1. Which keyword is commonly used to define a value or function in F#?

  1. var
  2. let
  3. define
  4. val

Answer: B) let

Explanation:

The let keyword is used to bind names to values and functions in F#. Recursive functions can be defined using let rec.

2. Which keyword is required when defining a recursive F# function?

  1. recursive
  2. loop
  3. rec
  4. self

Answer: C) rec

Explanation:

The rec keyword allows a function to refer to itself. For example, a recursive function is defined using let rec factorial n = ....

3. What is the result of the following F# expression?

let square x = x * x
square 5
  1. 10
  2. 15
  3. 20
  4. 25

Answer: D) 25

Explanation:

The function multiplies its argument by itself. Therefore, square 5 evaluates to 25.

4. Which statement about F# functions is correct?

  1. Functions cannot be stored in variables
  2. Functions can be treated as values
  3. Functions must always belong to classes
  4. Functions cannot be passed as arguments

Answer: B) Functions can be treated as values

Explanation:

F# treats functions as first-class values. They can be assigned to names, passed as arguments, returned from other functions, and stored in data structures.

5. Which syntax represents an anonymous function in F#?

  1. lambda x => x + 1
  2. fun x -> x + 1
  3. function x = x + 1
  4. anonymous(x) = x + 1

Answer: B) fun x -> x + 1

Explanation:

The fun keyword introduces a lambda expression in F#. The expression fun x -> x + 1 represents a function that adds one to its argument.

6. Which operator is commonly used to pipe a value into a function in F#?

  1. ->
  2. |>
  3. =>
  4. <-

Answer: B) |>

Explanation:

The forward pipe operator |> passes the value on its left as an argument to the function on its right.

7. What does the following expression evaluate to?

5 |> (fun x -> x * 2)
  1. 5
  2. 7
  3. 10
  4. 25

Answer: C) 10

Explanation:

The value 5 is passed to the anonymous function, which multiplies it by 2. The result is 10.

8. What is a key characteristic of type inference in F#?

  1. Every variable must always have an explicit type
  2. The compiler can infer types from expressions
  3. Types are determined only at runtime
  4. F# does not use static typing

Answer: B) The compiler can infer types from expressions

Explanation:

F# uses static type inference. The compiler analyzes expressions and function usage to determine types without requiring explicit type annotations in many cases.

9. Which of the following creates an F# list containing three integers?

  1. (1, 2, 3)
  2. [1; 2; 3]
  3. [|1; 2; 3|]
  4. {1; 2; 3}

Answer: B) [1; 2; 3]

Explanation:

F# lists are written using square brackets with elements separated by semicolons. Arrays use [| ... |].

10. Which statement correctly describes an F# list?

  1. It is mutable by default
  2. It is an ordered immutable collection
  3. It can contain values of unrelated types without a common type
  4. It always provides O(1) indexed access

Answer: B) It is an ordered immutable collection

Explanation:

An F# list is an ordered, immutable series of elements of the same type. F# lists are implemented as singly linked lists, so indexed access requires traversal.

11. Which operator adds an element to the front of an F# list?

  1. ::
  2. @
  3. +
  4. ++

Answer: A) ::

Explanation:

The cons operator :: adds an element to the beginning of a list. For example, 1 :: [2; 3] produces [1; 2; 3].

12. Which operator concatenates two F# lists?

  1. ::
  2. @
  3. ||
  4. &&

Answer: B) @

Explanation:

The @ operator concatenates two compatible F# lists into a new list.

13. Which F# function applies a transformation to every element of a list?

  1. List.map
  2. List.find
  3. List.head
  4. List.empty

Answer: A) List.map

Explanation:

List.map applies a specified function to each element and returns a new list containing the transformed values.

14. What does List.filter do?

  1. Sorts a list
  2. Removes all elements from a list
  3. Returns elements satisfying a predicate
  4. Converts a list into an array

Answer: C) Returns elements satisfying a predicate

Explanation:

List.filter takes a predicate function and returns a new list containing only the elements for which the predicate returns true.

15. Which syntax creates an F# array?

  1. [1; 2; 3]
  2. (1; 2; 3)
  3. [|1; 2; 3|]
  4. {|1; 2; 3|}

Answer: C) [|1; 2; 3|]

Explanation:

F# arrays use [| and |]. Unlike lists, arrays are mutable and provide constant-time indexed access.

16. Which F# collection is represented by the type seq<'T>?

  1. List
  2. Array
  3. Sequence
  4. Tuple

Answer: C) Sequence

Explanation:

seq<'T> represents an F# sequence. It is an alias for System.Collections.Generic.IEnumerable<'T> and supports lazy evaluation of elements.

17. Which expression creates a sequence containing the integers from 1 through 5?

  1. [1..5]
  2. seq { 1 .. 5 }
  3. array { 1 .. 5 }
  4. sequence(1,5)

Answer: B) seq { 1 .. 5 }

Explanation:

A sequence expression uses seq { ... }. The range 1 .. 5 generates the values from 1 through 5.

18. Which statement about F# sequences is correct?

  1. All sequence elements must be computed immediately
  2. Sequences are always mutable
  3. Sequence elements can be computed on demand
  4. Sequences can contain only integers

Answer: C) Sequence elements can be computed on demand

Explanation:

F# sequences are commonly used for lazy or on-demand computation. Individual elements are generated as required during enumeration.

19. What is the purpose of the F# option type?

  1. To represent a value that may or may not exist
  2. To represent only numeric values
  3. To create mutable variables
  4. To define classes

Answer: A) To represent a value that may or may not exist

Explanation:

The option type represents either a value using Some or the absence of a value using None.

20. Which two cases are associated with the F# option type?

  1. Yes and No
  2. Some and None
  3. True and False
  4. Value and Empty

Answer: B) Some and None

Explanation:

An F# option has two cases: Some(value) when a value exists and None when it does not.

21. Which F# construct is primarily used for branching based on patterns?

  1. switch
  2. match
  3. select
  4. choose

Answer: B) match

Explanation:

The match expression compares a value against a series of patterns and evaluates the expression associated with the first matching pattern.

22. What does the underscore _ represent in an F# pattern?

  1. A numeric zero
  2. A wildcard pattern
  3. A null reference
  4. An empty list

Answer: B) A wildcard pattern

Explanation:

The underscore is the wildcard pattern. It matches any value without binding that value to a name.

23. What is the purpose of a pattern guard in F#?

  1. To define a class
  2. To add an additional Boolean condition to a pattern
  3. To create a loop
  4. To convert a value to a string

Answer: B) To add an additional Boolean condition to a pattern

Explanation:

A pattern can include a when clause. The guard must evaluate to true for that pattern branch to be selected.

24. What does the following pattern match?

match value with
| x :: xs -> ...
| [] -> ...
  1. Only arrays
  2. A non-empty list and an empty list
  3. Only tuples
  4. Only strings

Answer: B) A non-empty list and an empty list

Explanation:

The x :: xs cons pattern decomposes a non-empty list into its head and tail, while [] matches an empty list.

25. Which syntax defines a tuple containing two values in F#?

  1. [1; 2]
  2. (1, 2)
  3. [|1; 2|]
  4. {1, 2}

Answer: B) (1, 2)

Explanation:

Tuples are written using parentheses with comma-separated values. Unlike lists, tuple elements can have different types.

26. Which F# type is designed to represent an aggregate of named values?

  1. Record
  2. Sequence
  3. Option
  4. Delegate

Answer: A) Record

Explanation:

F# records represent simple aggregates of named values. Record fields are accessed using their field names.

27. Which syntax correctly defines an F# record?

  1. type Person = { Name: string; Age: int }
  2. record Person(Name, Age)
  3. type Person(Name: string, Age: int)
  4. struct Person = (Name, Age)

Answer: A) type Person = { Name: string; Age: int }

Explanation:

F# records are declared with the type keyword followed by a record definition containing named fields and their types.

28. What is a discriminated union in F#?

  1. A type whose value can be one of several named cases
  2. A collection that stores only integers
  3. A mutable array
  4. A special type of loop

Answer: A) A type whose value can be one of several named cases

Explanation:

Discriminated unions allow a value to represent one of several named cases, with each case optionally carrying associated data.

29. Which syntax correctly declares a simple F# discriminated union?

  1. type Result = Success | Failure
  2. union Result(Success, Failure)
  3. enum Result { Success, Failure }
  4. type Result(Success, Failure)

Answer: A) type Result = Success | Failure

Explanation:

F# discriminated unions are declared with type followed by named cases separated by the pipe symbol.

30. Which discriminated union case can carry an integer value?

  1. Success
  2. Success of int
  3. Success: int
  4. Success(int)

Answer: B) Success of int

Explanation:

A discriminated union case can carry associated data using the of keyword, such as Success of int.

31. Which expression correctly creates an option containing the integer 10?

  1. Option(10)
  2. Some 10
  3. Value 10
  4. Option.SomeValue 10

Answer: B) Some 10

Explanation:

Some is the option case that wraps an existing value. Therefore, Some 10 has type int option.

32. Which keyword is used to define an F# module?

  1. namespace
  2. module
  3. package
  4. group

Answer: B) module

Explanation:

The module keyword groups related F# values, functions, types, and other declarations.

33. Which statement about F# modules is correct?

  1. They can contain only functions
  2. They can group values, types, and functions
  3. They can contain only classes
  4. They cannot be nested

Answer: B) They can group values, types, and functions

Explanation:

An F# module is a grouping of related code constructs such as values, types, functions, and do bindings. Modules can also be nested.

34. Which keyword is used to define a class type in F#?

  1. class
  2. type
  3. object
  4. define

Answer: B) type

Explanation:

F# uses the type keyword for class definitions. For example, type Person(name: string) = ... defines a class.

35. Which keyword is used to declare an interface in F#?

  1. interface
  2. contract
  3. protocol
  4. abstract-interface

Answer: A) interface

Explanation:

F# interfaces define sets of related members that implementing types must provide. Interface members are generally declared using abstract member.

36. Which keyword is used to declare an abstract interface member in F#?

  1. virtual
  2. abstract
  3. interface
  4. override

Answer: B) abstract

Explanation:

F# interface declarations use abstract member to specify members that implementing types must provide.

37. Which keyword is used to implement an inherited or virtual member in an F# type?

  1. replace
  2. override
  3. implement
  4. virtualize

Answer: B) override

Explanation:

The override keyword is used when a derived F# type provides an implementation for an inherited abstract or virtual member.

38. What is the purpose of the mutable keyword in F#?

  1. It makes a value recursive
  2. It allows a binding to be changed after initialization
  3. It converts a value to an option
  4. It creates a constant

Answer: B) It allows a binding to be changed after initialization

Explanation:

F# values are immutable by default. A binding declared with mutable can be reassigned using the <- operator.

39. What is the purpose of the F# <- operator when used with a mutable value?

  1. Function composition
  2. Assignment
  3. Pattern matching
  4. List concatenation

Answer: B) Assignment

Explanation:

The <- operator assigns a new value to a mutable binding or mutable property.

40. Which keyword is commonly used for resource management when the resource should be disposed automatically?

  1. using
  2. dispose
  3. use
  4. release

Answer: C) use

Explanation:

The F# use binding is designed for values that implement System.IDisposable. The resource is disposed when the binding goes out of scope.

41. What does partial application mean in F#?

  1. Calling a function without compiling it
  2. Supplying fewer arguments to create a new function
  3. Removing a function parameter
  4. Calling a function recursively

Answer: B) Supplying fewer arguments to create a new function

Explanation:

F# supports partial application. Providing some arguments to a function can produce another function that accepts the remaining arguments.

42. What does function composition using the >> operator do?

  1. Runs two functions in parallel
  2. Composes functions from left to right
  3. Compares two functions
  4. Converts a function to a value

Answer: B) Composes functions from left to right

Explanation:

The >> operator composes two functions so that the output of the first function becomes the input to the second function.

43. Which keyword is used to introduce an asynchronous computation expression in F#?

  1. async
  2. await
  3. future
  4. parallel

Answer: A) async

Explanation:

The async { ... } computation expression is used to construct asynchronous computations in F#. Operations such as let! can bind the result of another asynchronous computation.

44. What does let! commonly do inside an F# computation expression?

  1. Defines a class
  2. Binds the result of a computation
  3. Declares a mutable variable
  4. Creates a record

Answer: B) Binds the result of a computation

Explanation:

Inside computation expressions, let! binds the result produced by another computation according to the rules defined by the computation-expression builder.

45. Which keyword returns a value from an F# computation expression?

  1. yield
  2. return
  3. result
  4. output

Answer: B) return

Explanation:

The return keyword produces the final value of a computation expression according to the builder's Return implementation.

46. What is the purpose of the yield keyword in an F# sequence expression?

  1. To define a class
  2. To produce an element of the sequence
  3. To terminate the program
  4. To create an exception

Answer: B) To produce an element of the sequence

Explanation:

Within a sequence expression, yield produces an individual element. The resulting sequence can generate those elements during enumeration.

47. What does the following F# code return?

let result =
    match Some 10 with
    | Some x -> x * 2
    | None -> 0
  1. 0
  2. 10
  3. 20
  4. None

Answer: C) 20

Explanation:

The value is Some 10, so the first pattern matches and binds x to 10. The expression x * 2 therefore produces 20.

48. What is the output of the following F# code?

let numbers = [1; 2; 3; 4]
let result = numbers |> List.filter (fun x -> x % 2 = 0)
printfn "%A" result
  1. [1; 3]
  2. [2; 4]
  3. [1; 2]
  4. [3; 4]

Answer: B) [2; 4]

Explanation:

The predicate keeps only numbers whose remainder after division by 2 is zero. Therefore, the resulting list contains 2 and 4.

49. What does the following F# code evaluate to?

let classify n =
    match n with
    | x when x > 0 -> "Positive"
    | x when x < 0 -> "Negative"
    | _ -> "Zero"

classify -7
  1. Positive
  2. Negative
  3. Zero
  4. Error

Answer: B) Negative

Explanation:

The first guard fails because -7 is not greater than zero. The second guard succeeds because -7 is less than zero, so the function returns "Negative".

50. What is the result of the following F# code?

type Shape =
    | Circle of float
    | Rectangle of float * float

let area shape =
match shape with
| Circle r -> System.Math.PI * r * r
| Rectangle (w, h) -> w * h

let result = area (Rectangle (5.0, 4.0))
  1. 9.0
  2. 20.0
  3. 25.0
  4. 62.83

Answer: B) 20.0

Explanation:

The value passed to area is the Rectangle case with width 5.0 and height 4.0. Pattern matching selects the rectangle branch, which calculates 5.0 * 4.0, producing 20.0.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2026 www.includehelp.com. All rights reserved.