News for hackers. Stuff that matters.
Re:All Programming Languages are Wrong (2018) by dkersten on Wednesday February 12, 2020 @03:02AM (#22306844)
Slightly off topic, but what should a map or flatMap implementation on boolean do? Presumably run on true and skip on false? That’s not really what I expect from map (that it’s filtered the input). I could imagine book.filter.map as a way to conditionally execute
Re:All Programming Languages are Wrong (2018) by bedobi on Wednesday February 12, 2020 @03:50AM (#22307098)
Haha you're putting me on the spot here, I guess I haven't really thought too deeply about the specifics!

Maybe flatMap would return true only if all chained booleans are true?

Bimap would allow you to provide functions for what to do in true and false case?

Fold would allow you to turn true or false into a single type?

I'm sure someone more experienced in FP can weigh in with something more correct! :p

Re:All Programming Languages are Wrong (2018) by karmakaze on Wednesday February 12, 2020 @04:53AM (#22307459)
I rather like that, `if condition` is a 0/1 iteration with no input. flatMap can return empty, what should map return when run on false, None?
Re:All Programming Languages are Wrong (2018) by mrgriffin on Wednesday February 12, 2020 @12:44PM (#22310865)
I'd probably think of Bool as being isomorphic to Maybe (), which would mean your map implementation looks a bit like:

    map :: Bool -> (() -> b) -> Maybe b
    map True f = Just (f ())
    map False _ = Nothing
Or, in Haskell because you've got laziness you could go with:

    map :: Bool -> b -> Maybe b
Which already exists as a combination of Control.Monad.guard and Data.Functor.(<$).

    map tf b = b <$ guard tf