On Tue, Mar 24, 2009 at 8:29 PM, Miguel Mitrofanov <miguelimo38@yandex.ru> wrote:
takeList ns xs = evalState (mapM (State . splitAt) ns) xs

or even

takeList = evalState . map (State . splitAt)

would be much clearer than both versions.

Brilliant. As a newbie, I knew all these functions, I have used them all. When I saw both initial implementations, I tried to write what you did, but failed, I didn't see the pattern, failed to pick the correct functions in my head, failed to make the puzzle.

I guess that is the real power of Haskell. In imperative languages, the more you practice, the better you get in avoiding the imperative pitfalls. In functional languages, more practice really results in more and more productivity because you recognize the patterns; the design patterns are not just thoughts but real functions you can reuse.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe