Miranda Error无法在第12行与[char]统一[[char]]

时间:2011-10-03 17:10:45

标签: functional-programming miranda

使用miranda进行编码时遇到的问题只是功能编程的新手,所以如果我不是一个容易出错的错误,那么我就会很难打动

无论如何我在第12行遇到一个错误,因为我的想法是unifyin 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"]

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

1 个答案:

答案 0 :(得分:4)

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

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

read file的类型为[char],字典的类型为[[char]]

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

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

也许您希望在将(read file)追加到dictionary之前将其拆分为单词。然后你会将[[char]]追加到[[char]],这样就可以了。

注意我对米兰达一无所知 - 这个答案是基于查看你的代码,你给出的错误信息,以及我对Haskell的经验(我在那里做了很多)类似的错误)。