In: Computer Science
1. In your own words explain what a Monad is and why it is important in the composition of functions.
2. In terms of Reflex-FRP explain the following three terms
3. Explain what a Monad Transformer does and why it is important
4. What is the difference between a partial function and a function that gives a valid result for any member of its type.
1) Monads is which allows us to defer some part of our program's evaluation while still writing functions that take one value and return one value. In the case of Maybe , we're deferring what to do about missing values or values that we cannot produce.
The reason why Monads are important in the composition of functions is that they provide a uniform framework for describing a wide range of programming language features including, for example, state, I/O, continuations, exceptions, parsing and non-determinism, without leaving the frame- work of a purely functional language.
2) Reflex-FRP given three terms explanation:
a) A "Behavior" is a value that may change over time. This might be the current position of the mouse pointer, or the current score in a game.
b) An "Event" is a thing that can happen. This might be something at a low level of abstraction, like a mouse being clicked. Or it might be something at a much higher level, such as moving a chess piece. But it happens at specific times, yielding specific values that describe what occurred.
c) A "Dynamic" is both a behavior and an event. It has a value over time, but the changes in that value are observable as an event that fires when updates are made.
3) Monad transformers are used to compose features encapsulated by monads such as state, exception handling, and I/O in a modular way.
Monad Transformer is important because it's IO allows world-changing side effects. Monad transformer modifies the behaviour of an underlying monad. Most of the monads in the "mtl library" have transformer equivalents. The transformer version of a monad has the same name, with a T stuck on the end. For example, the transformer equivalent of State is StateT, it adds mutable state to an underlying monad. The WriterT monad transformer makes it possible to write data when stacked on top of another monad.
4) The difference between a partial function and a function that gives a valid result for any member of its type:
Partial function: A function that is not defined for some inputs of the right type, that is, for some of a domain. For instance, division is a partial function since division by 0 is undefined. A partial function is a binary relation over two sets that associates to every element of the first set at most one element of the second set; it is thus a functional binary relation. It generalizes the concept of a function by not requiring every element of the first set to be associated to exactly one element of the second set.
Function that gives a valid result for any member of its type: A function which is defined for all inputs of the right type, that is, for all of a domain. Total functions are functions that give you a valid return value for every combination of valid arguments. They never throw errors and they don’t require checks of the return value. Total functions help you write more robust code and simpler code, free from defensive checks and errors.