News for hackers. Stuff that matters.
Re:Functor, Applicative, and Monad by dllthomas on Wednesday September 18, 2019 @01:08PM (#21007465)
"Conclusively" is probably a little strong. You're relying not just on the type, but also the name - the type alone isn't enough here, even without resorting to bottom, and even when requiring every piece be meaningfully used. For instance, with the same type we can write:

    doubleIf :: Applicative m => (a -> m Bool) -> [a] -> m [a]
    doubleIf f values = case values of
        [] -> pure []
        x:xs -> prepend x <$> f x <*> doubleIf f xs
      where
        prepend :: a -> Bool -> [a] -> [a]
        prepend x True xs = x:x:xs
        prepend x False xs = x:xs
Re:Functor, Applicative, and Monad by zeugmasyllepsis on Wednesday September 18, 2019 @01:50PM (#21007994)
Maybe a simpler way to illustrate this is two different functions built off of filter:

`keep`: Given a predicate and a collection, filter the collection to retain only items for which predicate evaluates to true.

`discard`: Given a predicate and a collection, filter the collection to discard items for which the predicate evaluates to false.

These are two very reasonable functions that would have the exact same signature, would be appropriate for the same arguments, but have two different behaviors!

Re:Functor, Applicative, and Monad by dllthomas on Wednesday September 18, 2019 @03:46PM (#21009237)
Honestly, you could reasonably call either of those "filter" :D