Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5.
- 7.
- [(1,2,3),(4,5,6),(7,8,9),(10,11,12)].
- digitToInt :: String -> Int
- getLine :: IO String
- readFile :: FilePath -> IO String
- lines:: String -> [String]
- init :: [a] -> [a]
- read :: (Read a) => String -> a
- run :: IO (Int, Int, [(Int,Int,Int)])
- run = do
- contents <- readFile "text.txt" -- use '<-' here so that 'contents' is a String
- let [a,b,c] = lines contents -- split on newlines
- let firstLine = read (init a) -- 'init' drops the trailing period
- let secondLine = read (init b)
- let thirdLine = read (init c) -- this reads a list of Int-tuples
- return (firstLine, secondLine, thirdLine)
- line <- getLine
- :type line
- line :: String
- :type getLine
- getLine :: IO String
- main = do
- putStrLn "How much do you love Haskell?"
- amount <- getLine
- putStrln ("You love Haskell this much: " ++ amount)
- :type readFile
- readFile :: FilePath -> IO String
- yourdata <- readFile "samplefile.txt"
- :type yourdata
- text :: String
- fmap doTheRightThingWithString readStringFromFile
- import Control.Applicative
- ...
- doTheRightThingWithString <$> readStringFromFile
- import Control.Monad
- ...
- liftM doTheRightThingWithString readStringFromFile
- readStringFromFile >>= string -> return (doTheRightThingWithString string)
- readStringFromFile >>= string -> return $ doTheRightThingWithString string
- readStringFromFile >>= return . doTheRightThingWithString
- return . doTheRightThingWithString =<< readStringFromFile
- do
- ...
- string <- readStringFromFile
- -- ^ you escape String from IO but only inside this do-block
- let result = doTheRightThingWithString string
- ...
- return result
- myParser :: String -> Foo
- readFile "thisfile.txt"
- fmap myParser (readFile "thisfile.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement