10 Oct 2012 09:27
CPS Streams
jeff p <mutjida <at> gmail.com>
2012-10-10 07:27:36 GMT
2012-10-10 07:27:36 GMT
{-
I've always thought that the essence of iteratees is just CPS (I have
no desire to argue the merits of this statement, and I preemptively
concede to anyone who disagrees with this), so I decided to experiment
with a direct CPS version of streams. The resulting code turned out
nicer than I'd expected, so I'm writing about it in case anyone else
finds it interesting or instructive (it seems to me that Haskellers
tend to shy away from CPS). I'm pretty sure this technique is not new,
but a cursory search didn't turn up quite the same thing. I'd be
interested in any pointers to this somewhere else, as well any general
feedback about this.
-}
{-# LANGUAGE ScopedTypeVariables, TupleSections #-}
import Control.Applicative hiding (empty)
import Control.Arrow
import Control.Exception
import Control.Monad (unless)
import Data.Attoparsec.Text
import Data.Text
import Data.Text.IO
import Prelude hiding (catch, getLine, lines, length, null, putStrLn,
readFile, splitAt)
import qualified Prelude as P
import System.IO (IOMode(..), hClose, hIsClosed, withFile)
import System.IO.Error hiding (catch)
(Continue reading)
RSS Feed