Question

having a problem with coding with miranda am just a newbie to functional programming so slap me hard if ive dont an easy mistake so i learn

anyway i a getting an error on line 12 with having a problem with unifyin char with char my idea is to check is something is spelt right by filtering it with the dictionary wich would be both an list of words and another list from a file added together

this is my line 12

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

and this is the rest of my program so far

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"]

so could anyone point out where i'v gone wrong?

Was it helpful?

Solution

I've never used Miranda, but having used Haskell, it looks like the problem is that you're trying to append a string and a list of strings; however, I guess that ++ needs two lists of the same type (as in Haskell):

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

But read file is of type [char], and dictionary is of type [[char]].

Trying to substitute these into the type signature for ++ causes the type error:

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

Maybe you want to split (read file) into words before you append it to dictionary. Then you would be appending [[char]] to [[char]], which will work just fine.

Note I don't know anything about Miranda -- this answer is based on looking at your code, the error message you gave, and my experience with Haskell (where I've made oodles of similar mistakes).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top