4

米兰达编码有问题我只是函数式编程的新手,所以如果我没有一个简单的错误,请狠狠地打我一巴掌,所以我学习了

无论如何,我在第 12 行遇到错误,因为 unifyin char 和 char 有问题我的想法是通过使用字典过滤来检查是否拼写正确,这将是单词列表和文件中的另一个列表加在一起

这是我的第 12 行

= [filter (= typed) ((read file) ++ dictionary)]

这是到目前为止我的程序的其余部分

filename == [char]
word  == [ char ]
dictionary :: [ word ]



spell:: filename -> filename -> [ char ]
look:: word -> filename ->[[[ char ]]]


look typed file
= [filter (= typed) ((read file) ++ dictionary)]

dictionary =
["aardvark","bell","camp","dictionary","editor","file","ground",
"grounds","help","intelligent","joint","kettle","light","memory",
"nettle","orange","quite","research","standard","terminal",
"umbrella","violin","water","xenon","yellow","zoo","aaa","abb",
"acc","add","aee"]

所以有人能指出我哪里出错了吗?

4

1 回答 1

3

我从来没有用过 Miranda,但是用过 Haskell,看起来问题是你试图附加一个字符串和一个字符串列表;但是,我想这++需要两个相同类型的列表(如在 Haskell 中):

(++) :: [a] -> [a] -> [a]

但是read file是类型[char],字典是类型[[char]]

尝试将这些替换为类型签名++会导致类型错误:

(++) :: [char] -> [[char]] -> ?? -- type error!!

也许您想(read file)在将其附加到dictionary. 然后你将附加[[char]][[char]],这将工作得很好。

注意我对米兰达一无所知——这个答案是基于查看你的代码、你给出的错误信息以及我使用 Haskell 的经验(我犯了很多类似的错误)。

于 2011-10-03T18:55:58.737 回答