Reading file into types - Haskell

后端 未结 3 984
北恋
北恋 2020-12-04 04:26

Right now I have two types:

type Rating = (String, Int)

type Film = (String, String, Int, [Rating])

I have a file that has this data in it

3条回答
  •  执笔经年
    2020-12-04 04:44

    Is this homework?

    You might find these functions useful:

    • readFile :: FilePath -> IO String
    • lines :: String -> [String]
    • break :: (a -> Bool) -> [a] -> ([a], [a])
    • dropWhile :: (a -> Bool) -> [a] -> [a]
    • null :: [a] -> Bool
    • read :: Read a => String -> a

    Remember that String is the same as [Char].

    Some clues:

    • dropWhile null will get rid of empty lines from the start of a list
    • break null will split a list into the leading run of non-empty lines, and the rest of the list

提交回复
热议问题