Question 1. Explain What Is Haskell?
Haskell is an advanced functional programming language, providing easy integration with other languages, built-in concurrency, and rich libraries. Haskell programming is centered on evaluating expressions rather than executing instructions.
Question 2. Mention What Are The Benefits Of Haskell Expression?
Benefits of Haskell expression:
- In Haskell, variable, data structure etc. is immutable
- Haskell expression has no issues like updating global variables or printing to the screen
- Everytime calling the same function with the same argument will result in the same output
- It is possible to decouple I/O from the rest of the code, reducing programming error; it is very important feature of Haskell programming
- Without telling Haskell what type of data to read, read the function in the program will direct what to read.
Question 3. Mention What Are Monads In Haskell?
A monad in Haskell is just a type for which the >>= operation is defined. Haskell’s I/O is based on Monads. It’s a specific way of binding operations together or in other words, it’s a way of wrapping things and provide a method to perform operations on the wrapped stuff without unwrapping it.
Question 4. List Out Different Types Of Monads Can Be In Haskell?
Each monad has its own application of the bind function like:
- Failure Monad
- Error Monad
- List Monad
- Reader Monad
- State & Writer Monad
Question 5. Explain The Type System For Haskell?
- While working with Haskell, the first step involves in writing a Haskell program is usually to write down all the types.
- Haskell language is like a transcript just by looking at the function’s type it will tell you about what the function might do Turns run-time errors into compile time errors, it is better to fix errors up front.
Question 6. Explain How Function Is Defined In Haskell?
Function definition in Haskell consists of a number of condition equations. At the beginning of each, after the function name, there are patterns that show to which data each equation applies. After that there are multiple clauses, representing different cases and a where clause to hold local definitions.
Question 7. Explain What Is The Difference Between $ (dollar Sign) And . (dot) ?
In Haskell, $ sign operator is used to avoid parenthesis, anything that appears after it will take precedence over anything that comes before. For example, (putStrLn .show) (1+1) can be replaced by putStrLn . show $ 1+1. While,. (dot) primary function is to chain function and not to avoid parenthesis.
Question 8. Explain Why Haskell Algebraic Data Types Are Closed?
Haskell algebraic data types are closed because it makes it a lot easier to write total functions. Functions that produce a result, for all possible values of its type.
Question 9. Explain What Is Prelude In Haskell?
In Haskell, prelude is a module that consists of a bunch of standard definitions that gets implicitly imported into Haskell program.
Question 10. List Out The Numeric Types In The Haskell “prelude”?
In Haskell, there are five numeric types that includes
Int: It is an integer having at least 30 bits of precision
Integer: It is an integer having unlimited precision
Float: It is a single precision floating point number
Double: It is a double point precision floating point number
Rational: It is a fraction type with no rounding error
Question 11. Mention How Data Types Are Combined In Haskell?
In Haskell, data types are combined in two ways
List: It goes in [square brackets]
Tuples: It goes in (parenthesis)
Question 12. Mention What Are The Types Of Polymorphism You Will Encounter In Haskell?
In Haskell, there are two types of polymorphism:
Parametric Polymorphism: A function is parametrically polymorphic, if it behaves equally for all types, in at least one of its type parameters
Bounded Polymorphism: You have bounded polymorphism or ad hoc, if you have custom behavior that you want to have for certain set of types
Question 13. Explain How You Can Implement “ord” For Algebraic Data Types In Haskell?
In Haskell, the best way to implement “ord” is just to add deriving (Eq, Ord) to the type’s definition.
Question 14. Explain Why “lazy Evaluation” In Haskell Is Useful?
In Hazkel, lazy evaluation is useful due to following reasons:
- Values will not be computed if they are not going to be used
- Haskell makes sure that the order in which the expressions are evaluated will never affect their result.
- Also, it allows the infinite lists
Question 15. Explain What Is The Difference Between “data” And “new Type” In Haskell?
Newtype: It guarantees that your data will have exactly the same representation at runtime, like the type that you wrap
Data: It declares a brand new data structure at runtime
Question 16. Mention What Is The Difference Between Haskell (++) And (:)?
(:) operator: It is known as the “cons” operator and is used to append a head element to a list
(++) operator: It is a list concatenation operator, and it takes two operands and combine them into a single list
Python Interview Questions
C++ Interview Questions
PHP Interview Questions
C Interview Questions
Java Interview Questions
Python Interview Questions
Lisp programming Interview Questions