Re:The list monad in Perl and Python
by rogerallen on Tuesday August 04, 2015 @10:44AM
(#10003661)
Anyone care to explain why this doesn't return a gigantic list of empty arrays and one solution tuple? I don't see where the non-solution []'s are removed from the list.
[ Parent
| on HN ]
There's an explanation in the earlier article (http://blog.plover.com/prog/haskell/monad-search.html), but it's because the `bind`/`bd` function takes the solution arrays from its callees, and concatenates the arrays into one big array of solutions, which it then returns to its caller.
In the Python code I think this is built into the behavior of the `+=` operator.
In the Perl code it's part of the way the `map` call works; it combines what would be `concat . map` in Haskell.
Re:The list monad in Perl and Python
by rogerallen on Tuesday August 04, 2015 @11:37AM
(#10004087)
Thanks for explaining and thanks for the post. It was helpful seeing an example of why you might want to use a monad.