Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This seems overcomplicated. Why wrap String (which is already a monoid) inside Maybe? You can just use concat; if the result is the empty string then print the number. If you want it to work for any monoid, then use mconcat, and test for equality to mempty.

And why introduce monad comprehensions if you're just introducing monoids?



> Why wrap String (which is already a monoid) inside Maybe?

Because it's a bit easier to write the tail end of the logic in generic terms. You can go talk to c_wraith on Freenode#haskell if you want.

> You can just use concat; if the result is the empty string then print the number. If you want it to work for any monoid, then use mconcat, and test for equality to mempty.

You can find other discussions about why flexibility is important.

> And why introduce monad comprehensions if you're just introducing monoids?

Because it's a really nice syntax? Compared to explicitly using guard, anyways.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: