GPT Haskell Flashcards

1
Q

What is the type of the expression head [1 2 3]

A

head [1 2 3] has type Num a => a.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the type of the function f x y = x + y

A

The type of f is f :: Num a => a -> a -> a.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the => symbol mean in a type signature

A

The => symbol indicates a constraint on the types that can be used in the function. For example in the type (Ord a Num b) => a -> b -> b the constraint Ord a means that the type a must be an instance of the Ord type class and the constraint Num b means that the type b must be an instance of the Num type class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a type class in Haskell

A

A type class in Haskell is a set of types that support a set of operations. For example the Eq type class represents types that support equality testing and the Num type class represents numeric types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a polymorphic function in Haskell

A

A polymorphic function in Haskell is a function that can work with multiple types. Polymorphic functions are often defined using type variables which can represent any type. For example the head function has the type [a] -> a which means that it can take a list of any type and return an element of that type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a higher-order function in Haskell

A

A higher-order function in Haskell is a function that takes other functions as arguments or returns a function as its result. For example the map function takes a function and a list as arguments and applies the function to each element of the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is currying in Haskell

A

Currying is the process of transforming a function that takes multiple arguments into a sequence of functions that each take a single argument. For example the function f x y = x + y can be curried to give the function f' x = \y -> x + y.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a lambda function in Haskell

A

A lambda function in Haskell is a nameless function that is defined using the syntax \arg1 arg2 ... -> body. Lambda functions are often used as arguments to higher-order functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the type of the Maybe type constructor

A

The Maybe type constructor has the type Maybe a = Just a | Nothing where a is a type variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a newtype in Haskell

A

A newtype in Haskell is a type that is defined using the newtype keyword and is used to create a new type with a different name from an existing type. Newtypes are used to create distinct types that are semantically equivalent to existing types but have different runtime representations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a type synonym in Haskell

A

A type synonym in Haskell is a type that is defined using the type keyword and is used to give an existing type a new name. Type synonyms are used to create aliases for types and do not create new types at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a monad in Haskell

A

A monad in Haskell is a type constructor that represents a computation that may have a value or may fail with an error. Monads provide a way to sequence actions and handle errors and are used extensively in Haskell for implementing side-effecting computations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the do notation in Haskell

A

The do notation in Haskell is a syntactic sugar for writing monadic code and allows expressions to be written in a more imperative style. The do notation is often used with monads to sequence actions and handle errors in a concise and readable way.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the Either type in Haskell

A

The Either type in Haskell is a type constructor that represents a value that can be either of two types. The Either type is often used to represent computations that can either succeed with a value or fail with an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a functor in Haskell

A

A functor in Haskell is a type that implements the Functor type class which defines the fmap function. The fmap function allows functions to be applied to values inside a functorial context such as a list or a tree. Functors are used extensively in Haskell to abstract over the structure of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a fold in Haskell

A

A fold in Haskell is a function that takes a binary function a list and a starting accumulator value and applies the binary function to the elements of the list and the accumulator from left to right to reduce the list to a single value. Folds are a fundamental operation in Haskell and are used to perform many types of list transformations.

17
Q

What is a traversable in Haskell

A

A traversable in Haskell is a type that implements the Traversable type class which defines the traverse function. The traverse function allows functions to be applied to values inside a traversable structure such as a list or a tree and return a functorial value such as a list or a Maybe value. Traversables are used extensively in Haskell to abstract over the structure of data.

18
Q

What is the Writer monad in Haskell

A

The Writer monad in Haskell is a monad that represents a computation that produces a value along with a log of intermediate results. The Writer monad is often used to implement computations that produce a result and an annotated log of intermediate steps such as debug information or statistics.

19
Q

What is the type of the Maybe type constructor

A

The Maybe type constructor has the type Maybe a = Just a | Nothing where a is a type variable.

20
Q

What is a newtype in Haskell

A

A newtype in Haskell is a type that is defined using the newtype keyword and is used to create a new type with a different name from an existing type. Newtypes are used to create distinct types that are semantically equivalent to existing types but have different runtime representations.

21
Q

What is a type synonym in Haskell

A

A type synonym in Haskell is a type that is defined using the type keyword and is used to give an existing type a new name. Type synonyms are used to create aliases for types and do not create new types at runtime.

22
Q

What is a monad in Haskell

A

A monad in Haskell is a type constructor that represents a computation that may have a value or may fail with an error. Monads provide a way to sequence actions and handle errors and are used extensively in Haskell for implementing side-effecting computations.

23
Q

What is the do notation in Haskell

A

The do notation in Haskell is a syntactic sugar for writing monadic code and allows expressions to be written in a more imperative style. The do notation is often used with monads to sequence actions and handle errors in a concise and readable way.

24
Q

What is the Either type in Haskell

A

The Either type in Haskell is a type constructor that represents a value that can be either of two types. The Either type is often used to represent computations that can either succeed with a value or fail with an error.

25
Q

What is a functor in Haskell

A

A functor in Haskell is a type that implements the Functor type class which defines the fmap function. The fmap function allows functions to be applied to values inside a functorial context such as a list or a tree. Functors are used extensively in Haskell to abstract over the structure of data.

26
Q

What is a fold in Haskell

A

A fold in Haskell is a function that takes a binary function a list and a starting accumulator value and applies the binary function to the elements of the list and the accumulator from left to right to reduce the list to a single value. Folds are a fundamental operation in Haskell and are used to perform many types of list transformations.

27
Q

What is a traversable in Haskell

A

A traversable in Haskell is a type that implements the Traversable type class which defines the traverse function. The traverse function allows functions to be applied to values inside a traversable structure such as a list or a tree and return a functorial value such as a list or a Maybe value. Traversables are used extensively in Haskell to abstract over the structure of data.

28
Q

What is the Writer monad in Haskell

A

The Writer monad in Haskell is a monad that represents a computation that produces a value along with a log of intermediate results. The Writer monad is often used to implement computations that produce a result and an annotated log of intermediate steps such as debug information or statistics.

29
Q

What is the Maybe monad in Haskell

A

The Maybe monad in Haskell is a monad that represents a computation that may have a value or may be Nothing. The Maybe monad is often used to represent computations that may fail and provides a way to handle failure by returning a default value or propagating the error.

30
Q

What is a monoid in Haskell

A

A monoid in Haskell is a type that implements the Monoid type class which defines the mempty and mappend functions. The mempty function represents the identity element for the mappend function and the mappend function represents a binary operation that is associative and has an identity element. Monoids are used extensively in Haskell for various types of aggregation and combination.

31
Q

What is the State monad in Haskell

A

The State monad in Haskell is a monad that represents a computation that can read and write a state value. The State monad is often used to implement computations that have an internal state such as a counter or a cache and provides a way to modify the state and access its value in a composable way.

32
Q

What is the Reader monad in Haskell

A

The Reader monad in Haskell is a monad that represents a computation that can read a value from a shared environment. The Reader monad is often used to implement computations that depend on a shared context such as configuration data or a database connection and provides a way to access the context in a composable way.

33
Q

What is the IO monad in Haskell

A

The IO monad in Haskell is a monad that represents a computation that can perform side effects such as reading from or writing to the external world. The IO monad is the standard way to perform input/output in Haskell and provides a way to isolate side-effecting computations from pure ones.

34
Q

What is a monad transformer in Haskell

A

A monad transformer in Haskell is a type that adds additional functionality to an existing monad. Monad transformers are often used to stack multiple monads together to create a composite monad with multiple capabilities. For example the MaybeT transformer adds the ability to fail to an existing monad and the StateT transformer adds the ability to read and write a state value to an existing monad.

35
Q

What is the Applicative type class in Haskell

A

The Applicative type class in Haskell is a type class that represents types that can be applied to values inside a functorial context. The Applicative type class defines the pure and <*> functions which allow values and functions to be combined in a way that is similar to the fmap function of the Functor type class but with additional flexibility and power.

36
Q

What is the Alternative type class in Haskell

A

The Alternative type class in Haskell is a type class that represents types that can be combined using an alternative operation. The Alternative type class defines the empty and <|> functions which allow values to be combined in a way that is similar to the mappend function of the Monoid type class but with additional flexibility and power.

37
Q

What is a type family in Haskell

A

A type family in Haskell is a type-level function that allows the definition of types that depend on values. Type families are defined using the type family keyword and are used to define type-level functions that can be used to parameterize types with values. Type families are a powerful feature of Haskell and are used in a variety of contexts such as type-level programming and generic programming.