The result of the filtering to the right of >>= must be of monadic
type, you can use `return' for this. In hbi:

   > getDirectoryContents "." >>= (return . filter (\(x:_) -> x /= '.')); 
   ["GoodNews","BadNews","OldNews","mbox"]

   > 
   
Or, by using `fmap', `head', and a section:

   > filter ((/='.') . head) `fmap` getDirectoryContents ".";          
   ["GoodNews","BadNews","OldNews","mbox","NewNews"]

   > 

(Use `map' instead of `fmap' if you don't have Haskell98.)

/M


Simon Raahauge DeSantis writes:
 > I'm working on a little toy program in hbc (now that I have a haskell
 > compiler running I decided to give it a try ;), but I seem to have run into
 > a monad problem. Here's the snippet in particular (and the results from
 > evaluation in hbi):
 > > getDirectoryContents "." >>= filter (\(x:_) -> x /= '.');
 > [65] Cannot unify types:
 >     Prelude.IO
 > and (Prelude.[])
 >  in  (>>=) (getDirectoryContents ".") (filter (\I -> 
 > case I of {
 >   Prelude.[] -> Pfail "No match in Pinteractive"
 > | (:) x I4625 -> (/=) x '.'
 > }
 > ))
 > 
 > (The idea here is to filter out all the dot files from the directory
 > listing)
 > Unfortunately I can't make hide or hair of this. Is this because the
 > function being used with filter would break when given an empty list (or is
 > that Pfail bit there to handle that breaking?)
 > TIA
 > -- 
 > -Simon Raahauge DeSantis


Reply via email to