18 Matching Annotations
  1. Sep 2026
    1. An essential thing to know before trying to type in the above function is that Haskell delimits the scope of multi-line function definitions (and all multiline expressions) with indentation

      Haskell uses indentation to know which lines belong to a block code

    2. () (called unitA type with exactly one value, (), used to indicate the absence of meaningful return value, similar to void in other languages. )

      void in Java / C / TypeScript

    1. Tail Call Optimisation

      normal recursion creates a new stack frame for every recursive call. Tail recursion can be converted by the compiler into a loop, so it doesn't keep growing the stack

      TCO does not means faster, its just for reducing stack usage

    2. Exercise What other functions called in the JavaScript code generated for the above definition of main are curried? Why?

      add x y = x + y

      Currying allows a function to receive arguments one at a time, which enables partial application and makes functions eaiser to reuse and compose

    3. Exercise If one didn’t happen to like the fact that function chaining with the $ operator reads right to left, how would one go about creating an operator that chains left to right? (Hint: infixl is a thing and you will need to make a slightly different apply function also).

      operator called |>

      x |> f === f x

      opposite orientation of $

      as $ uses apply f x = f x

      x |> f becomes applyLeft x f = f x

      Ans: infixl 0 applyLeft as |>

    4. in Haskell, putting the argument after the function left-to-right unless operators change the grouping

      replace every $ with brackets main = log $ show $ map fibs $ 1..10 equivalent to main = log (show (map fibs (1..10)))

      map fibs (1..10) apply fibs to every number in the list

    5. pattern matchingA mechanism in functional programming languages to check a value against a pattern and to deconstruct data. ,

      fibs 0 = 1 ^ ^ ^ | | | | | result | pattern function

      Haskell commonly uses pattern matching instead of writing if/else for cases where the input's structure or value determines what to do.

    1. REQ1 Heath points (HP) = hit point which is in Farmer constructor

      GameEntity class is used to control the actor's statistic

      unconscious(map) removes the Farmer from the map

    1. High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend upon details. Details should depend on abstractions.

      Depend on abstractions rather than concrete implementation

    1. Liskov Substitution Principle

      A child/subclass should be able to replace its parent/superclass without breaking the program's expected behaviour.