[Haskell-cafe] Re: about Haskell code written to be "too smart"
apfelmus at quantentunnel.de
Wed Mar 25 02:54:58 EDT 2009
Dan Piponi wrote:
>> Miguel Mitrofanov wrote:
>>> takeList = evalState . mapM (State . splitAt)
>> However, ironically, I stopped using them for pretty
>> much the same reason that Manlio is saying.
> Are you saying there's a problem with this implementation? It's the
> only one I could just read immediately. The trick is to see that
> evalState and State are just noise for the type inferencer so we just
> need to think about mapM splitAt. This turns a sequence of integers
> into a sequence of splitAts, each one chewing on the leftovers of the
> previous one. *Way* easier than both the zipWith one-liner and the
> explicit version. It says exactly what it means, almost in English.
I couldn't agree more. In other words, splitAt is really to be thought
of as a function that lives in the state monad.
More information about the Haskell-Cafe