Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Yair Chuchem <yairchu <at> gmail.com>
Subject: ANNOUNCE: generator 0.5.1
Newsgroups: gmane.comp.lang.haskell.general
Date: Wednesday 15th July 2009 13:33:21 UTC (over 8 years ago)
A new "generator" package has been uploaded to Hackage.

It implements an alternative list monad transformer, a list class, and  
related functions.

The difference from mtl/transformers's ListT is that
mtl is a monadic action that returns a list:
newtype ListT m a = ListT { runListT :: m [a] }
generator's is a monadic list:
data ListItem l a =  Nil | Cons { headL :: a, tailL :: l a }
newtype ListT m a = ListT { runListT :: m (ListItem (ListT m) a) }
A short example program which reads numbers from the user and  
interactively sums them up:
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))
I also wrote an example/blog-post about using ListT to add an undo  
option to the classic game of "hamurabi":
http://mashebali.blogspot.com/2009/07/charlemagne-disraeli-and-jefferson.html

Another interesting observation is that "ListT [] a" is a tree of "a"s.
The module Data.List.Tree includes functions to prune and search such  
trees (dfs, bfs, bestFirstSearchOn, etc).
This can be useful for modularizing code that uses the list monad for  
combinatoric search by decoupling tree creation from processing and  
pruning.
 
CD: 3ms