Skip to content

Commit 5912347

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

File tree

1 file changed

+61
-29
lines changed

1 file changed

+61
-29
lines changed

backend/middle-1/haskell.md

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
# Haskell for Middle-1
22

3-
## Basic type classes
4-
5-
* Functors
6-
* What is covariance and contravariance in the context of functors and category theory?
7-
* What are the negative and positive positions?
8-
* What types can be both covariant functors and contravariant?
9-
* What are invariant functors?
10-
* Contrafunctor (Contravariant functor)
11-
* What is the signature of `contramap` function?
12-
* Make an example of instance definition for some ADT.
13-
* What is the semantic meaning of applying `contramap`?
14-
* Bifunctor
15-
* What is the signature of `bimap` function?
16-
* What ADT's do have the `Bifunctor` instance?
17-
* Is a bifunctor covariant or contravariant on type variables applied to it?
18-
* Profunctor
19-
* What is the signature of `dimap` function?
20-
* Write an instance implementation for `(->)`.
21-
* Name a few practical use cases (at least one).
22-
* Which of type variables applied to a profunctor appear in negative and which in positive position?
3+
## Functors
4+
5+
* What is covariance and contravariance in the context of functors and category theory?
6+
* What are the negative and positive positions?
7+
* What types can be both covariant functors and contravariant?
8+
* What are invariant functors?
9+
* Contrafunctor (Contravariant functor)
10+
* What is the signature of `contramap` function?
11+
* Make an example of instance definition for some ADT.
12+
* What is the semantic meaning of applying `contramap`?
13+
* Bifunctor
14+
* What is the signature of `bimap` function?
15+
* What ADT's do have the `Bifunctor` instance?
16+
* Is a bifunctor covariant or contravariant on type variables applied to it?
17+
* Profunctor
18+
* What is the signature of `dimap` function?
19+
* Write an instance implementation for `(->)`.
20+
* Name a few practical use cases (at least one).
21+
* Which of type variables applied to a profunctor appear in negative and which in positive position?
2322

2423
#### Resources
2524

26-
* Functors
27-
* [(Co-contra) variance](https://www.fpcomplete.com/blog/2016/11/covariance-contravariance)
28-
* [I love profunctors](https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors)
29-
* [Functoriality (just not bad article about functors)](https://bartoszmilewski.com/2015/02/03/functoriality/)
25+
* [(Co-contra) variance](https://www.fpcomplete.com/blog/2016/11/covariance-contravariance)
26+
* [I love profunctors](https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors)
27+
* [Functoriality (just not bad article about functors)](https://bartoszmilewski.com/2015/02/03/functoriality/)
28+
* An example of using profunctors:
29+
[`Statement`](https://hackage.haskell.org/package/hasql-1.5.0.2/docs/Hasql-Statement.html#t:Statement)
30+
type from the `hasql` library.
31+
* typeclasses.com on [contravariance](https://typeclasses.com/contravariance)
32+
* typeclasses.com on [profunctors](https://typeclasses.com/profunctors)
33+
* An easy explanation of `Contravariant`: a `Functor` may be thought as it
34+
"contains" or "produces" values, while a `Contravariant` "consumes" them. Pay
35+
attention on the polarity term.
3036

3137
## Type classes
3238

@@ -77,7 +83,7 @@
7783
* What are Pattern Synonyms and what are they used for?
7884
* Can we pattern match on concrete values (constants) in the right-hand side?
7985
* Where can Pattern Synonyms occur? Can we declare them locally, inside of functions?
80-
* What is the restriction on type variables with Bidirectional Pattern Synonyms?
86+
* What is the restriction on parameters of Bidirectional Pattern Synonyms?
8187
* What are Unidirectional Pattern Synonyms?
8288
What are their constraints comparing with Bidirectional Pattern Synonyms?
8389
* What are Explicitly Bidirectional Pattern Synonyms?
@@ -121,15 +127,34 @@ How can we bundle Pattern Synonyms with datatypes in export and import lists?
121127

122128
## Laziness
123129

124-
* How is value from evaluated thunk stored (are we allowed to avoid redundant reevaluations)?
125-
* Enumerate cases where thunk with ADT will be evaluated.
126-
* What is the irrefutable pattern and how does it work?
127-
* What does the `sprint` function do?
130+
* Describe the process of evaluating a thunk and storing the evaluated value.
131+
* After a thunk is fully evaluated, will the GHC runtime evaluate it again?
132+
* What is a black hole and what problem does it solve?
133+
* What kind of thunks are black holes used for?
134+
* Enumerate cases where a thunk returning an ADT will be evaluated.
135+
* What is an irrefutable pattern and how does it work?
136+
* Where are patterns in Haskell irrefutable by default?
137+
* Which patterns are irrefutable:
138+
1. `f (Just a) = ...`
139+
1. `let (Just a) = ...`
140+
1. `where (Just a) = ...`
141+
1. `g (MyType a) = ...` where `MyType` is a `newtype` declaration.
142+
1. `g (MyType a) = ...` where `MyType` is a `data` declaration.
143+
1. `f a = ...`
144+
1. `f _ = ...`
145+
* When can irrefutable patterns be helpful? Hint: you may describe why
146+
[`Data.List.partition`](https://hackage.haskell.org/package/base-4.16.0.0/docs/src/Data.OldList.html#partition)
147+
uses them.
148+
* What does the `sprint` command do in `ghci`?
128149

129150
#### Resources
130151

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

134159
## Exceptions
135160

@@ -144,6 +169,8 @@ How can we bundle Pattern Synonyms with datatypes in export and import lists?
144169
Why do we need it?
145170
* What is the purpose of `safe-exceptions` library? Which exception handling problems does it address?
146171
Why is `unliftio` considered safer by the author of `safe-exceptions`?
172+
* When does the problem of rethrowing asynchronous exceptions as synchronous
173+
happen and how can it be solved?
147174
* Describe a problem which arises when handling exceptions and using functions like `bracket` with stateful monadic stacks.
148175
* How is it solved in `monad-control` library?
149176
* How is it solved in `unliftio` library?
@@ -202,13 +229,18 @@ What are the commands which help with that?
202229
* What is a `Traversal`?
203230
* What is an `Iso`?
204231
* Why is `Monoid` constraint required in `view` for traversals?
232+
* Is a `Prism` a `Lens`, a `Traversal` a `Lens`, an `Iso` a `Lens`, a
233+
`Traversal` an `Iso`, a `Prism` an `Iso`, or vice versa?
234+
* Is the `traverse` method of the `Traversable` class a `Traverse`?
205235
* What are the lens laws?
206236
* Why do lenses fit well for composing?
207237
* How operators are grouped by name (which ones are started with `^`, which ones contain `~`, `.` (dot), `%`, `=`)?
208238
* What combinators are purposed for working in `State` monad?
209239
Why is it convenient?
210240
* What is the goal of the microlens library?
211241
When to use it and when do not?
242+
* When and why is it better to use `generic-lens` and `optics` libraries? What
243+
libraries can we use together?
212244

213245
#### Resources
214246

0 commit comments

Comments
 (0)