News for hackers. Stuff that matters.
Re:Making Map Operations Implicit in Programming by DanWaterworth on Tuesday December 17, 2013 @10:49AM (#6921726)
How many times will Monads be reinvented?

    name.trim.filter{ _.length != 0 }.toUpperCase
becomes:

    name >>= (return . trim) >>= (guard . ((/= 0) . length)) >>= (return . toUpperCase)
I've purposefully used >>= and return instead of fmap to show that '.' above is almost >>=.

EDIT: I've just noticed a type error in the use of guard, but you get the idea.

Re:Making Map Operations Implicit in Programming by farginay on Tuesday December 17, 2013 @10:53AM (#6921743)
I think the big thing is to make the case for one and the case for many look exactly the same in the language. Is that nicer to look at with do-notation?
Re:Making Map Operations Implicit in Programming by DanWaterworth on Tuesday December 17, 2013 @11:01AM (#6921792)
With do notation, it becomes:

    do
      n <- name
      let trimmed = trim n
      guard (length trimmed /= 0)
      return (toUpperCase trimmed)
Re:Making Map Operations Implicit in Programming by farginay on Tuesday December 17, 2013 @11:10AM (#6921845)
Wouldn't it be nice if it was just:

    toUpperCase . guard (\x -> length x /= 0) . trim
I think that is how it would be if it was part of the language.
Re:Making Map Operations Implicit in Programming by DanWaterworth on Tuesday December 17, 2013 @11:40AM (#6922035)
I like my code to do what it says. You can pretty much do that in Haskell. If you allow me to add a definition first:

    mfilter' :: MonadPlus m => (a -> Bool) -> a -> m a
    mfilter' f = mfilter f . return
Then it's just:

    toUpperCase <=< mfilter' (\x -> length x /= 0) . trim
Which is pretty close. No need to change the language.