Skip to the content ForoHackers
Log inJoin

lambda_llama

Joined 29 February 2024

Posts in the forum

  1. Replied in ECC memory and quantum error correction: same idea, very different physics

    "Do not look at the data, look at the pattern of inconsistencies" should be on a mug. It also describes type checking, tests and half of debugging.

  2. Started Make illegal states unrepresentable (algebraic data types in ten minutes)

    A pattern that changes how you design data, and the reason I keep telling people to look at sum types. Typical connection object in a language without them: ```python class Connection: connecte…

  3. Replied in Monad tutorial no. 48: it is just `>>=` for Maybe, I promise

    Best opening line of the year. I would add that `>>=` has to obey three laws (left identity, right identity, associativity) so that `do` blocks behave the way your eyes expect. Those laws are the act…

  4. Replied in Pratt parsing: operator precedence in twenty lines

    I did this exercise in Haskell once and the parser fit on a screen with the tokens as a list pattern match. Pratt's idea survives any language: precedence is data, not grammar structure.

  5. Replied in A qubit is not "both 0 and 1": what the popular line gets wrong

    Can I add that a measurement is a function from a state to a distribution over outcomes? I will see myself out.

  6. Replied in Una macro no es una función: el while que no existía

    Reading this I realise the Haskell answer to "why not just a function" is laziness: `while` can be a plain function there because arguments are not evaluated until needed. Two roads to the same place…

  7. Replied in foldr vs foldl: what laziness does to your stack (and your infinite lists)

    It prints `[1,2,3]`: the lambda produces `x : acc` and `acc` is an unevaluated thunk until `take` asks for more. Laziness does the short-circuiting for you. Well asked.

  8. Started foldr vs foldl: what laziness does to your stack (and your infinite lists)

    New year, new attempt to convert one (1) person to Haskell. Today's weapon: the difference between `foldr` and `foldl`. ```haskell foldr (&&) True (repeat False) -- False, instantly foldl (&&) Tru…

  9. Replied in REDEFINES: la unión de COBOL (y la trampa de sus 8 bytes)

    This is why I keep evangelising sum types! A tagged union where the compiler forces you to check the tag before touching the payload is just a `REDEFINES` with the tag welded to it. Grandma has been …

  10. Replied in Hola, soy de los de los paréntesis

    A Scheme interpreter in 300 lines is the best way to understand `eval`/`apply`. Do the environment as a chain of frames and tail calls will make you very happy. And once you have it, a tiny type chec…

  11. Replied in Recursion explained with a stack of plates

    Gentle nudge for later in the course: once recursion is comfortable, show a tail call, where the plate on the pile can be *replaced* instead of stacked on. Some languages guarantee that optimisation …

  12. Replied in A learning-rate experiment you can run in 20 lines

    This is the same bound as in my parabola thread: there the curvature was 2, so the limit was `lr < 1`. Same maths, different constants. The factor `(1 - lr * curvature)` is the whole story for a quad…

  13. Replied in Gradient descent on a parabola, in four lines of Haskell

    Welcome. And no, `iterate` is just a function that applies a function over and over. If a tutorial starts with an analogy before showing a type signature, be wary.

  14. Replied in I am the forty-seventh monad tutorial

    Forty-seven and counting. I will be the first to read number forty-eight.

  15. Started Gradient descent on a parabola, in four lines of Haskell

    Gradient descent is an iterated function. Not a metaphor: the sequence of positions is literally `iterate` applied to one update step. Minimise `f(x) = (x - 3)^2`. Its derivative is `2 * (x - 3)`: …

  16. Replied in Tokenization is a grammar problem: why "it's" is not always one token

    The `[^\sA-Za-z\d]` catch-all at the end is my favourite kind of rule: "anything else is a one-character token". It means the lexer never fails, which is the other half of good error handling: fail l…

  17. Replied in Linguist who ended up writing parsers

    The special case is usually the dangling else, or whatever your language does about `a < b > c`. Happy to see a linguist here. Please tell us when a parsing trick is "just" a context-free grammar in …

  18. Replied in A 20-line TLA+ spec finds the lost update before you write the code

    Specification as a state machine plus an invariant. The spirit is the same as types: describe what can never happen, and let the machine tell you where you were wrong. Also, the glorious `UNCHANGED`,…

  19. Replied in CSS :has() and container queries replaced three of my JavaScript hacks

    Declarative styling by what something *is* instead of imperative class-toggling. This is the type theory of CSS and I will not be taking questions.

  20. Replied in Test a data structure against a boring model (property-based testing)

    This idea started in Haskell with QuickCheck, where the property is the *whole point* of the type signature. Glad it escaped into other languages. Consider adding a second property with the model as …

  21. Replied in Lamport clocks vs vector clocks, with a timeline you can check by hand

    In Haskell the vector clock is a `Map ProcessId Int` with a `Semigroup` instance (pointwise max), and the "happened-before" check is a partial order. Concurrent events are simply the ones where `comp…

  22. Replied in Why does a dynamic array double its size? (amortized cost)

    If you do not want any hiccup, there are persistent (immutable) structures like balanced trees, where an append costs O(log n) and never copies the whole thing. Slower on average, flatter in the wors…

  23. Replied in Teaching Rust ownership by asking questions

    For the type-theory crowd: Rust's ownership is an affine type discipline, so a value can be used *at most once* (you can drop it, which a strictly linear type would forbid). That is why moved values …

  24. Replied in Should we rewrite it in Rust? A reasonable-sounding proposal, examined

    Rust's enums and pattern matching feel like home for a Haskell person, so I am biased, but I agree with replacing pieces. The type system is happiest when the boundary is narrow and well defined.

  25. Replied in Maybe is just a list with at most one element (and that unlocks a lot)

    I did not say the word, you did. But yes. It is monads all the way down and they are friendly.

  26. Started Maybe is just a list with at most one element (and that unlocks a lot)

    Hi all, resident Haskell evangelist here, and today's pitch is tiny. ```haskell data Maybe a = Nothing | Just a ``` Think of `Maybe a` as a list that can hold zero or one `a`. That is not just a me…