[Haskell-beginners] How do I map a String and a IO String?
Francesco Ariis
fa-ml at ariis.it
Thu Jun 29 13:16:02 UTC 2017
On Thu, Jun 29, 2017 at 02:33:22PM +0200, Jona Ekenberg wrote:
> I want to replace lines with the content of a file if the line is a filename
Hello Jonas, you want to user `return`:
λ> :t return
return :: Monad m => a -> m a
which lifts a simple value inside a monad (in this case, a -> IO a), like
this:
lineOrIO :: String -> IO String
lineOrIO cs | (isPrefixOf "./" cs) = readFile cs
| otherwise = return cs
If this is not a school assignment, consider replacing `isPrefixOf "./"`
with something from `System.Directory`.
Does this help?
More information about the Beginners
mailing list