<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>This sounds similar to ChoiceT from the monadLib package. Did you know ChoiceT?</div><div><br></div><div>greetings,</div><div>Sjoerd</div><br><div><div>On Jul 15, 2009, at 3:33 PM, Yair Chuchem wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>A new "generator" package has been uploaded to Hackage.</div><div><br></div><div>It implements an alternative list monad transformer, a list class, and related functions.</div><div><br></div><div>The difference from mtl/transformers's ListT is that</div><div><span class="Apple-style-span" style="font-family: Times; "><span class="Apple-style-span" style="font-family: Helvetica; "><div>mtl is a monadic action that returns a list:</div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><span class="keyword" style="color: blue; ">newtype</span> <span class="conid">ListT</span> <span class="varid">m</span> <span class="varid">a</span> <span class="keyglyph" style="color: red; ">=</span> <span class="conid">ListT</span> <span class="layout" style="color: red; ">{</span> <span class="varid">runListT</span> <span class="keyglyph" style="color: red; ">::</span> <span class="varid">m</span> <span class="keyglyph" style="color: red; ">[</span><span class="varid">a</span><span class="keyglyph" style="color: red; ">]</span> <span class="layout" style="color: red; ">}</span></span></div></span><pre><font class="Apple-style-span" color="#FF0000"><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Helvetica; white-space: normal; "><div>generator's is a monadic list:</div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><span class="keyword" style="color: blue; ">data</span> <span class="conid">ListItem</span> <span class="varid">l</span> <span class="varid">a</span> <span class="keyglyph" style="color: red; ">=<span class="Apple-style-span" style="color: rgb(0, 0, 0); ">  <span class="conid">Nil</span> <span class="keyglyph" style="color: red; ">|<span class="Apple-style-span" style="color: rgb(0, 0, 0); "> <span class="conid">Cons</span> <span class="layout" style="color: red; ">{</span> <span class="varid">headL</span> <span class="keyglyph" style="color: red; ">::</span> <span class="varid">a</span><span class="layout" style="color: red; ">,</span> <span class="varid">tailL</span> <span class="keyglyph" style="color: red; ">::</span> <span class="varid">l</span> <span class="varid">a</span> <span class="layout" style="color: red; ">}</span></span></span></span></span></span></div></span></font></pre><pre><font class="Apple-style-span" color="#FF0000"><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Times; white-space: normal; "><pre><a name="line-41"></a><a name="ListT"></a><span class="keyword" style="color: blue; ">newtype</span> <span class="conid">ListT</span> <span class="varid">m</span> <span class="varid">a</span> <span class="keyglyph" style="color: red; ">=</span> <span class="conid">ListT</span> <span class="layout" style="color: red; ">{</span> <span class="varid">runListT</span> <span class="keyglyph" style="color: red; ">::</span> <span class="varid">m</span> <span class="layout" style="color: red; ">(</span><span class="conid">ListItem</span> <span class="layout" style="color: red; ">(</span><span class="conid">ListT</span> <span class="varid">m</span><span class="layout" style="color: red; ">)</span> <span class="varid">a</span><span class="layout" style="color: red; ">)</span> <span class="layout" style="color: red; ">}</span>
</pre><div><font class="Apple-style-span" color="#FF0000" face="monospace"><span class="Apple-style-span" style="white-space: pre; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Helvetica; white-space: normal; "><div>A short example program which reads numbers from the user and interactively sums them up:</div><div><span class="Apple-style-span" style="font-family: sans-serif; "><pre style="font-size: 13px; "><span class="Apple-style-span" style="font-family: sans-serif; font-size: medium; white-space: normal; "><pre style="font-size: 12px; ">import Control.Monad.ListT (ListT)
import Data.List.Class (execute, joinM, repeat, scanl, takeWhile)
import Prelude hiding (repeat, scanl, takeWhile)

main =
  execute . joinM . fmap print .
  scanl (+) 0 .
  fmap (fst . head) .
  takeWhile (not . null) .
  fmap reads .
  joinM $ (repeat getLine :: ListT IO (IO String))</pre><pre style="font-size: 13px; "><span class="Apple-style-span" style="font-family: Helvetica; font-size: medium; white-space: normal; "><div>I also wrote an example/blog-post about using ListT to add an undo option to the classic game of "hamurabi":</div><div><a href="http://mashebali.blogspot.com/2009/07/charlemagne-disraeli-and-jefferson.html">http://mashebali.blogspot.com/2009/07/charlemagne-disraeli-and-jefferson.html</a></div><div><br></div><div>Another interesting observation is that "ListT [] a" is a tree of "a"s.</div><div>The module Data.List.Tree includes functions to prune and search such trees (dfs, bfs, bestFirstSearchOn, etc).</div><div>This can be useful for modularizing code that uses the list monad for combinatoric search by decoupling tree creation from processing and pruning.</div><div><br></div></span></pre></span></pre></span></div></span></span></font></div></span></font></pre></span></div></div>_______________________________________________<br>Haskell mailing list<br><a href="mailto:Haskell@haskell.org">Haskell@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/haskell<br></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Sjoerd Visscher</div><div><a href="mailto:sjoerd@w3future.com">sjoerd@w3future.com</a></div><div><br></div></div></span><br class="Apple-interchange-newline"> </div><br></body></html>