Skip to content

Commit b0e7941

Browse files
middle-1/haskell: fix some questions, add new ones
1 parent c6b348d commit b0e7941

File tree

1 file changed

+63
-31
lines changed

1 file changed

+63
-31
lines changed

backend/middle-1/haskell.md

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<details>
55
<summary>List of contents</summary>
66

7-
- [Basic type classes](#basic-type-classes)
7+
- [Functors](#functors)
88
- [Type classes](#type-classes)
99
- [Types](#types)
1010
- [Polymorphic Kinds](#polymorphic-kinds)
@@ -19,34 +19,40 @@
1919
- [Kata](#kata)
2020

2121
</details>
22-
23-
## Basic type classes
24-
25-
* Functors
26-
* What is covariance and contravariance in the context of functors and category theory?
27-
* What are the negative and positive positions?
28-
* What types can be both covariant functors and contravariant?
29-
* What are invariant functors?
30-
* Contrafunctor (Contravariant functor)
31-
* What is the signature of `contramap` function?
32-
* Make an example of instance definition for some ADT.
33-
* What is the semantic meaning of applying `contramap`?
34-
* Bifunctor
35-
* What is the signature of `bimap` function?
36-
* What ADT's do have the `Bifunctor` instance?
37-
* Is a bifunctor covariant or contravariant on type variables applied to it?
38-
* Profunctor
39-
* What is the signature of `dimap` function?
40-
* Write an instance implementation for `(->)`.
41-
* Name a few practical use cases (at least one).
42-
* Which of type variables applied to a profunctor appear in negative and which in positive position?
22+
23+
## Functors
24+
25+
* What is covariance and contravariance in the context of functors and category theory?
26+
* What are the negative and positive positions?
27+
* What types can be both covariant functors and contravariant?
28+
* What are invariant functors?
29+
* Contrafunctor (Contravariant functor)
30+
* What is the signature of `contramap` function?
31+
* Make an example of instance definition for some ADT.
32+
* What is the semantic meaning of applying `contramap`?
33+
* Bifunctor
34+
* What is the signature of `bimap` function?
35+
* What ADT's do have the `Bifunctor` instance?
36+
* Is a bifunctor covariant or contravariant on type variables applied to it?
37+
* Profunctor
38+
* What is the signature of `dimap` function?
39+
* Write an instance implementation for `(->)`.
40+
* Name a few practical use cases (at least one).
41+
* Which of type variables applied to a profunctor appear in negative and which in positive position?
4342

4443
#### Resources
4544

46-
* Functors
47-
* [(Co-contra) variance](https://www.fpcomplete.com/blog/2016/11/covariance-contravariance)
48-
* [I love profunctors](https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors)
49-
* [Functoriality (just not bad article about functors)](https://bartoszmilewski.com/2015/02/03/functoriality/)
45+
* [(Co-contra) variance](https://www.fpcomplete.com/blog/2016/11/covariance-contravariance)
46+
* [I love profunctors](https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors)
47+
* [Functoriality (just not bad article about functors)](https://bartoszmilewski.com/2015/02/03/functoriality/)
48+
* An example of using profunctors:
49+
[`Statement`](https://hackage.haskell.org/package/hasql-1.5.0.2/docs/Hasql-Statement.html#t:Statement)
50+
type from the `hasql` library.
51+
* typeclasses.com on [contravariance](https://typeclasses.com/contravariance)
52+
* typeclasses.com on [profunctors](https://typeclasses.com/profunctors)
53+
* An easy explanation of `Contravariant`: a `Functor` may be thought as it
54+
"contains" or "produces" values, while a `Contravariant` "consumes" them. Pay
55+
attention on the polarity term.
5056

5157
## Type classes
5258

@@ -97,7 +103,7 @@
97103
* What are Pattern Synonyms and what are they used for?
98104
* Can we pattern match on concrete values (constants) in the right-hand side?
99105
* Where can Pattern Synonyms occur? Can we declare them locally, inside of functions?
100-
* What is the restriction on type variables with Bidirectional Pattern Synonyms?
106+
* What is the restriction on parameters of Bidirectional Pattern Synonyms?
101107
* What are Unidirectional Pattern Synonyms?
102108
What are their constraints comparing with Bidirectional Pattern Synonyms?
103109
* What are Explicitly Bidirectional Pattern Synonyms?
@@ -141,15 +147,34 @@ How can we bundle Pattern Synonyms with datatypes in export and import lists?
141147

142148
## Laziness
143149

144-
* How is value from evaluated thunk stored (are we allowed to avoid redundant reevaluations)?
145-
* Enumerate cases where thunk with ADT will be evaluated.
146-
* What is the irrefutable pattern and how does it work?
147-
* What does the `sprint` function do?
150+
* Describe the process of evaluating a thunk and storing the evaluated value.
151+
* After a thunk is fully evaluated, can the GHC runtime evaluate it again?
152+
* What is a black hole and what problem does it solve?
153+
* For what kind of thunks are black holes used?
154+
* Enumerate cases where a thunk returning an ADT is evaluated.
155+
* What is an irrefutable pattern and how does it work?
156+
* Where are patterns in Haskell irrefutable by default?
157+
* Which patterns are irrefutable:
158+
1. `f (Just a) = ...`
159+
1. `let (Just a) = ...`
160+
1. `where (Just a) = ...`
161+
1. `g (N a) = ...` where `newtype N a = N a`.
162+
1. `g (D a) = ...` where `data D a = D a`.
163+
1. `f a = ...`
164+
1. `f _ = ...`
165+
* When can irrefutable patterns be useful? Hint: you may describe why
166+
[`Data.List.partition`](https://hackage.haskell.org/package/base-4.16.0.0/docs/src/Data.OldList.html#partition)
167+
uses them.
168+
* What does the `sprint` command do in `ghci`?
148169

149170
#### Resources
150171

151172
* [Laziness from What I Wish I Knew When Learning Haskell](http://dev.stephendiehl.com/hask/#laziness)
152173
* [The GHC Runtime System - Ch. 4 Laziness](http://ezyang.com/jfp-ghc-rts-draft.pdf)
174+
* Haskell 2010 Language Report:
175+
* See p. 3.17.2 Informal Semantics of Pattern Matching in [Pattern Matching](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-580003.17)
176+
* [Irrefutable Patterns in Let Expressions](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-440003.12)
177+
* See p. 4.4.3.2 Pattern bindings in [Nested declarations](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-800004.4)
153178

154179
## Exceptions
155180

@@ -164,6 +189,8 @@ How can we bundle Pattern Synonyms with datatypes in export and import lists?
164189
Why do we need it?
165190
* What is the purpose of `safe-exceptions` library? Which exception handling problems does it address?
166191
Why is `unliftio` considered safer by the author of `safe-exceptions`?
192+
* When does the problem of rethrowing asynchronous exceptions as synchronous
193+
happen and how can it be solved?
167194
* Describe a problem which arises when handling exceptions and using functions like `bracket` with stateful monadic stacks.
168195
* How is it solved in `monad-control` library?
169196
* How is it solved in `unliftio` library?
@@ -235,13 +262,18 @@ What are the commands which help with that?
235262
* What is a `Traversal`?
236263
* What is an `Iso`?
237264
* Why is `Monoid` constraint required in `view` for traversals?
265+
* Is a `Prism` a `Lens`, a `Traversal` a `Lens`, an `Iso` a `Lens`, a
266+
`Traversal` an `Iso`, a `Prism` an `Iso`, or vice versa?
267+
* Is the `traverse` method of the `Traversable` class a `Traverse`?
238268
* What are the lens laws?
239269
* Why do lenses fit well for composing?
240270
* How operators are grouped by name (which ones are started with `^`, which ones contain `~`, `.` (dot), `%`, `=`)?
241271
* What combinators are purposed for working in `State` monad?
242272
Why is it convenient?
243273
* What is the goal of the microlens library?
244274
When to use it and when do not?
275+
* When and why is it better to use `generic-lens` and `optics` libraries? What
276+
libraries can we use together?
245277

246278
#### Resources
247279

0 commit comments

Comments
 (0)