suztomoの日記

To be a good software engineer

I'm trying to understand Iteratee section in [themonadreader.files.wordpress.com/2010/05/issue16.pdf:title=Monad Reader 16].

alternates :: IterV el [el]
alternates = fmap catMaybes . sequence . replicate 5 $ drop1keep1

-- replicate 5 $drop1keep1               :: [IterV el (Maybe el)]
-- sequence . replicate 5 $ drop1keep1   :: IterV el [ Maybe el ]                 Let's say this as X
-- fmap catMaybes X                      :: IterV el (([Maybe a] -> [a]) [ Maybe el ])
-- fmap catMaybes X                      :: IterV el [ el ]

Type notation

Suppose we have a type "V X Y Z", this should be understood as "(V X Y) Z". If V X Y is monad, the type has value Z.

z <- vxyz :: V X Y Z
z

The type of z is Z. And return always wrap a value with appropriate "context" (Monadic type) like:

somefunc :: V X Y Z
somefunc = do
    return z

Here, without specifying V X Y, "return" generates Monadic value of type "V X Y Z"