14 Apr
2005
14 Apr
'05
5:05 a.m.
ChrisK writes:
I was thinking to myself: What in Haskell would give me a "yield" command like a Python generator?
And the answer was "tell" in Control.Monad.Writer -- and I wrote some simple examples (see below).
Another possibility would be a continuation monad. import Control.Monad.Cont yield :: a -> Cont [a] () yield x = Cont (\c -> x : c ()) asGenerator :: Cont [a] v -> [a] asGenerator (Cont f) = f (const []) -- David Menendez <zednenem@psualum.com> | "In this house, we obey the laws <http://www.eyrie.org/~zednenem> | of thermodynamics!"