thanks for the explanations! I guess it's clear now<br><br><div class="gmail_quote">On Sat, Feb 4, 2012 at 3:02 PM, Chaddaï Fouché <span dir="ltr"><<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Sat, Feb 4, 2012 at 12:05 PM, David McBride <<a href="mailto:toad3k@gmail.com">toad3k@gmail.com</a>> wrote:<br>
> When you pass an argument to<br>
> readDir = findRegularFiles >>= readFiles<br>
><br>
> it expands to<br>
> readDir arg = (findRegularFiles >>= readFiles) arg<br>
><br>
> which fails because that expression takes no argument, only<br>
> findRegularFiles does. Honestly I can't think of any way to get that<br>
> argument in there without explicitly naming it.<br>
<br>
</div>I would say the problem is even before that, the expression<br>
"findRegularFiles >>= readFiles" is not well typed :<br>
<div class="im"><br>
(>>=) :: Monad m => m a -> (a -> m b) -> m b<br>
</div>specialized here in :<br>
(>>=) :: IO a -> (a -> IO b) -> IO b<br>
<br>
but :<br>
<br>
findRegularFiles :: FilePath -> IO [FilePath]<br>
<br>
so findRegularFiles is not of type "IO a", so can't be the first<br>
argument of (>>=) (or the second of (=<<) since that's just the<br>
flipped version).<br>
<br>
But there is a solution ! What you're searching here is a function of type :<br>
? :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c)<br>
<br>
A kind of monadic composition, there is an operator for that in<br>
Control.Monad since ghc 6.12 or even before :<br>
<br>
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c)<br>
<br>
so :<br>
<div class="im"><br>
> readDir = findRegularFiles >=> readFiles<br>
<br>
</div>or<br>
<div class="im"><br>
> readDir = readFiles <=< findRegularFiles<br>
<br>
</div>will work :)<br>
<font color="#888888"><br>
--<br>
Jedaï<br>
</font></blockquote></div><br>