我正试图做一个haskell问题,因为我正在努力学习Haskell.
这个问题给了我以下类型定义:
type Word = String
type Line = [Word]
type Book = [Line]
然后问题要求我定义一个函数索引:: Word - > Book - > [Int],它接受一个单词和一本书,并返回单词出现的行号.例如:
index "example" [["example", "town"], ["example", "cat", "this"]] = [1,2]
到目前为止,我已经使用了zip book [1 ..长度书]将行号附加到每一行,这样就可以给我了
[(["example","town"],1),(["example","cat","this"],2)]
那我怎么才提取行号呢?我假设我会使用列表推导,但我不知道该怎么做.