Hacker News new | ask | show | jobs
by internet_points 241 days ago
Agree about the list monad. I have never used it in actual code. I always felt it was so arbitrary, and "implicit", in the sense that if you haven't learnt beforehand that it makes "joins", then it's certainly not obvious that it should work that way

    λ> do { a <- [1,2]; pure a; }
    [1,2]
    -- oh so it returns the list unchanged
    λ> do { a <- [1,2]; b <- [3,4]; pure a; }
    [1,1,2,2]
    -- no what is this spooky action at a distance
    λ> do { a <- [1,2]; b <- [3,4]; pure [a]; }
    [[1],[1],[2],[2]]
    -- ...
    λ> do { a <- [1,2]; b <- [3,4]; c <- []; pure [a]; }
    []
    λ> do { a <- [1,2]; b <- [3,4]; c <- [5]; pure [a,b,c]; }
    [[1,3,5],[1,4,5],[2,3,5],[2,4,5]]