P

Philip Nilsson

philipnilsson.github.io · Personal blog · on HN since 2013

Philip Nilsson writes about functional programming, including monads, monoids, and semigroups, in his Badness10k blog.

What HN saysCommenters praise "Escaping Hell with Monads" as short and clear, and one teacher says it is what makes monads click for Haskell students.
19HN people shared it
12linked it in comments
15stories submitted
460story points
5 months agolast shared
2013people per year2026

Most-shared posts

  1. 1
    Escaping Hell with Monads
    10 people · 5 points · first shared 2017 · discussion on HN
  2. 2
    Escaping Hell with Monads (2017)
    6 people · 263 points · first shared 2017 · 213 comments on HN
  3. 3
    Algebraic Patterns – Monoid Morphism
    1 people · 86 points · first shared 2016 · 30 comments on HN
  4. 4
    Algebraic patterns – Semigroup
    1 people · 82 points · first shared 2016 · 39 comments on HN
  5. 5
    A functional solution to Twitter's waterflow problem
    1 people · 7 points · first shared 2013 · 2 comments on HN
  6. 6
    Algebraic Patterns – Monoid
    1 people · 4 points · first shared 2016 · discussion on HN
  7. 7
    Functional patterns – Identity element
    1 people · 3 points · first shared 2016 · discussion on HN
  8. 8
    Functional Patterns – Monoid
    1 people · 3 points · first shared 2016 · 1 comments on HN
  9. 9
    Algebraic Patterns – Semigroup
    1 people · 3 points · first shared 2016 · discussion on HN
  10. 10
    Algebraic Patterns – Category
    1 people · 2 points · first shared 2016 · discussion on HN
  11. 11
    Memento Spaghetti
    1 people · 1 points · first shared 2017 · discussion on HN
  12. 12
    A functional solution to Twitter's waterflow problem
    1 people · 1 points · first shared 2024 · discussion on HN
  13. 13
    Algebraic patterns monoid
    1 people · first shared 2019
  14. 14
    Badness10k
    1 people · first shared 2016
  15. 15
    Badness
    1 people · first shared 2014

What HN people wrote when they linked it

sodic · 2026-05-30
This is my favorite one, short and understandable: https://philipnilsson.github.io/Badness10k/posts/2017-05-07-escaping-h… I show it when I teach Haskell, and it's what usually makes it "click" for students. Probably because motivating examples are in normal imperative pseudocode.
JoelMcCracken · 2021-10-05
IMO, the best articles I know of on monads, which take two very different approaches: - http://www.jerf.org/iri/post/2958 - https://philipnilsson.github.io/Badness10k/escaping-hell-with-monads/
lmm · 2017-11-20
As a Scala programmer, Kotlin always feels like a language that frustratingly almost gets it, but is infuriatingly unwilling to listen to experience of what works in large codebases. Look at the examples on https://philipnilsson.github.io/Badness10k/escaping-hell-with-monads/ - I think Kotlin has literally every one of those ad hoc solutions built into the language, but stubbornly avoids making the generalisation. In small examples ad hoc solutions look great, but to succeed in large codebases a language needs a generality and consistency that Kotlin lacks. E.g. already there's no way to reuse logic between code paths that operate on Kotlin nullable types, Java Options (needed for compatibility with Java streams or more generally other JVM libraries), or rust-style Result types (for which there are several Kotlin libraries already, because it's a very useful concept and the language mostly has the facilities to support it), even though all three behave almost identically and you would often want to do the same thing in all three cases. But since the language won't let you represent what these types have in common, your only option is to copy/paste the code.
lgas · 2025-07-06
Out of curiosity, does this post help it stick any? https://philipnilsson.github.io/Badness10k/posts/2017-05-07-escaping-h…
hackingonempty · 2025-03-09
solatic · 2020-08-06
Everything old is new again. This challenge is basically why monads exist, because the monad allows you to cleanly separate between the state in which the algorithm is running and the algorithm itself. Reminds me of: https://philipnilsson.github.io/Badness10k/posts/2017-05-07-escaping-h… I wonder what poor abstraction the Go authors will come up with instead?
nyanpasu64 · 2020-08-06
> https://philipnilsson.github.io/Badness10k/posts/2017-05-07-escaping-h… Every "monadic solution" prints the same code block without explaining how it would work, the types of the various variables, the semantics of the <- operator. I didn't leave the page with an understanding of how monads achieve these tasks.
alipang · 2019-06-11
I've written a few blogs posts somewhat related to this at https://philipnilsson.github.io/Badness10k/, though it depends on the reader's level on whether they're a any good as an introduction.
leshow · 2019-03-27
Have a look at this blog post, it contains the bit I got that fold description from: https://philipnilsson.github.io/Badness10k/algebraic-patterns-monoid/ Back to my first post, I don't think it's not wrong to describe these operations as monoidal. Or to say that a monoidal operation implies something can be run in parallel, this whole thing feels a bit pedantic. edit: I don't know how you can say monoids for lists have nothing to do w/ empty lists considering the definition is literally: -- Identity laws x <> mempty = x mempty <> x = x Which is exactly what I posted before
benreesman · 2022-08-13
Ah no the migration I was referring to is `Applicative`: I just upgraded our "primary" Nix `devShell` to use `9.2.4` (`RecordDotSyntax` is finally here, may the thousand-year reign of the Glorious Glasgow Haskell Compiler commence! /s) and it's hitting me with deprecation notices about `return = ...` rather than `return = pure` and/or omitting and explicit `return`. Which makes sense, the rationale is at https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return… I remember when I was working on `Haxl` at FB in like, 2015 or 2016, it needed `ApplicativeDo` and that was like, quite the novelty in industrial Haskell (I think it was already a no-brainer to the research/OSS/etc. crowd). So mainstreaming `Applicative` into the effects hierarchy has been going on for 6 or 7 years that I know about, and I bet a lot longer than that (the paper introducing `Applicative` is from 2008: https://www.staff.city.ac.uk/~ross/papers/Applicative.html). There's an (admittedly oversimplified) sales deck for algebraic effects that I have found really effective at selling this stuff to open-minded non-FP hackers: https://philipnilsson.github.io/Badness10k/posts/2017-05-07-escaping-h… At the risk of inviting an old-fashioned HN brigade gang-tackle: I think it indirectly illustrates why Rust is going to end up going all-in and ditching the ?-notation. Please don't hurt me.
ParetoOptimal · 2022-03-06
> So really monads are essentially an abbreviated syntax? Chaining functions, where (some of) the arguments are hidden from the language syntax and inserted by the compiler? That's a part of it, for instance see: https://philipnilsson.github.io/Badness10k/posts/2017-05-07-escaping-h… I recently wrote a note related to this that had a useful exchange: >> When you see a "do" block, where do you look to figure out what it's actually doing? > If you need to know, you look at what consumes the result. If it's abstract (say it's a top level binding `... -> m a` where the m is abstract) *you don't _need_ to know "what it is actually doing" - it should be correct for any choice of* `m`. The behavior, and the "laws" or perhaps general far-reaching properties, are the more important part of Monads I think. > How does that relate to “pipe operator” as in https://github.com/tc39/proposal-pipeline-operator The items in the pipeline don't have a set of laws that let you know what's going on for sure without looking at the implementation I guess.
one-punch · 2020-01-26
The code is mostly pure Haskell (the do block, which most Haskellers are familiar with), with a few domain-specific elements (those led and delay “assignments” and the Stream type in this functional reactive programming framework arduino-copilot, whose meaning is specific to this Arduino application and most Haskellers have to guess). The short answer is that I could guess what it means. This `arduino-copilot` example really showcases one killer application of Haskell: writing eDSL (embedded domain-specific language) in Haskell. Haskell allows really high level abstraction: in particular, you can overload the operator which combines different statements in Haskell. In C/C++, the semicolon combines subsequent statements, Haskell even allows you to overload (give a new meaning to) the semicolon “operator” (think of overloading ; instead of overloading +). That is, in Haskell we can interpret differently how to combine subsequent statements in different contexts (such as null-checking, exception handling, async/await style concurrency, looping, or procedural state passing, etc., see the example below). However, when we “overload the semicolon operator”, we intuitively have some expectations: 1. We expect to be able to turn a value into a standalone statement (to inject a value as a single statement with that value, e.g., to turn the value “97” into the statement “97;”, and this operation is called return) 2. We expect to be able to use the result of a statement in the…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close