To be a good software engineer

Entries from 2011-11-20 to 1 day

Evaluate iteratee: length

As I'm not clear about how iteratees work, here I write down the step of "length" iteratee. length :: IterV el Int length = Cont (step 0) where step acc (El _) = Cont (step (acc+1)) step acc Empty = Cont (step acc) step acc EOF = Done acc …

Iteratee with IO

Around p.27 of Monad.Reader#16. type EnumeratorM el m a = IterV el a -> m (IterV el a) enumHandle :: Handle -> EnumeratorM Char IO a -- IterV Char a -> m (IterV Char a) enumHandle h iter = loop iter where loop :: IterV Char a -> IO (IterV …

Left-to-right Kleisli composition

Control.Monad (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c) f >=> g = \x -> f x >>= gOnce we define ">>=" operator, we can use this left-to-right Kleisli composition using the default implementation.

I'm trying to understand Iteratee section in [ Reader 16]. alternates :: IterV el [el] alternates = fmap catMaybes . sequence . replicate 5 $ drop1keep1 -- replicate 5 $drop…


CatMaybes concatenates maybe values in a list into one list. *Main> :t catMaybes catMaybes :: [Maybe a] -> [a] *Main> catMaybes [Just "a", Nothing, Nothing, Just "b"] ["a","b"]