Reading file into types - Haskell

后端 未结 3 983
北恋
北恋 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:58

    Haskell has a great way of using the types to find the right function. For instance: In Gregs answer, he wants you to figure out (among other things) how to convert the year of the film from a String to an Int. Well, you need a function. What should be the type of that function? It takes a String and returns an Int, so the type should be String -> Int. Once you have that, go to Hoogle and enter that type. This will give you a list of functions with similar types. The function you need actually has a slightly different type - Read a => String -> a - so it is a bit down the list, but guessing a type and then scanning the resulting list is often a very useful strategy.

提交回复
热议问题