diff --git a/backend/junior-3/haskell.md b/backend/junior-3/haskell.md index a3981a39..fc80a50d 100644 --- a/backend/junior-3/haskell.md +++ b/backend/junior-3/haskell.md @@ -44,7 +44,7 @@ * [Introduction to Tagless Final](https://serokell.io/blog/2018/12/07/tagless-final) -## TypeOperators and type classes extensions: +## TypeOperators and type classes extensions * `TypeOperators` * `FlexibleContexts` & `FlexibleInstances` @@ -127,7 +127,7 @@ * `ScopedTypeVariables` * What is the main goal of this extension? * Higher ranked types - * What is a "rank" of a function? + * What is a higher rank function? * Give examples of rank-1, rank-2, rank-3 functions. * What is the main goal of `RankNTypes` extension? * Can we create datatypes and newtypes with `RankNTypes`? @@ -197,18 +197,24 @@ * `1:(thunk)` * `1:2:(thunk)` * `1:2:3:[]` + * `thunk:thunk` * `15` * `\x -> x * 2` * `(\x -> x + 1) 3` * Can haskell evaluate in strict mode? -* Why strict functions in Haskell evaluate values to WHNF and not NF? +* Why are values in Haskell typically (when using `Strict`, `seq`, `foldl'`, + `modifyIORef'` etc) calculated to WHNF, not to NF? * What is the function `seq` (and operator `$!`)? * What is the function `deepseq` (and operator `$!!`)? * Could using `seq` change the returned value of the function? +* In which way does runtime behavior of the following expressions differ? + * ``a + b `seq` (a + b) : list`` + * ``let s = a + b in s `seq` s : list`` +* What are conditions when `seq` or `deepseq` can actually evaluate a value? * What is the GHC extension `BangPatterns`? - * Make examples when bang pattern is useless. - * Make examples when bang pattern has less power, than it could be supposed. - * Show the difference between this two definitions: + * Make examples when a bang pattern is useless. + * Do bang patterns force values to WHNF or NF? + * Show the difference between these two definitions: * `f1` ```haskell @@ -223,11 +229,13 @@ f2 x False = False ``` - * Does bang patterns force execution, when they are nested in constructors inside of `let` or `where` expressions? - * There is a `!` inside a `Maybe`, which is inside a `let` expression, and `let` expressions are lazy: + * Do bang patterns force execution when they are nested in constructors inside + `let` or `where` expressions? Does this force `a` to be evaluated or when + it does? ```haskell let (Just !a) = x in 1 + 1 + let (Just !a) = x in [a] ``` * What are the GHC extensions `Strict` and `StrictData`? @@ -260,6 +268,8 @@ * [Brief normal forms explanation with Haskell - Medium article](https://medium.com/@aleksandrasays/brief-normal-forms-explanation-with-haskell-cd5dfa94a157) * [All About Strictness. - FP Complete](https://www.fpcomplete.com/blog/2017/09/all-about-strictness) * [Does a function in Haskell always evaluate its return value? - Stackoverflow](https://stackoverflow.com/questions/27685224/does-a-function-in-haskell-always-evaluate-its-return-value) + * See "Learning to use `seq`", + [Real World Haskell](http://book.realworldhaskell.org/read/functional-programming.html) book. ## Lists