Created
August 30, 2011 10:25
-
-
Save o-sam-o/1180613 to your computer and use it in GitHub Desktop.
Haskell Compile Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad | |
| -- Compiles | |
| loadPaths :: FilePath -> IO [Int] | |
| loadPaths filename = do strings <- liftM lines $ readFile filename | |
| return (map read strings) | |
| -- Doesn't Compile | |
| loadPaths :: FilePath -> IO [Int] | |
| loadPaths filename = do strings <- liftM lines $ readFile filename | |
| map read strings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In a
dostatement for the monadmevery line (exception:letlines; see below) needs to have a type in the monad, i.e.m afor somea.In the second code, the last line has a type of
[Int], which is not in the monad. Usingreturnlifts the value to the monad so that the type isIO [Int].Using
liftMis okey, but could be avoided usinglet: