1

i am developing a small program but i'm stuck with an error.

I have an xml file that i parse, and i get the info that i want in with a function. Structure looks like this:

takeall :: [Element] -> (String,String,(String,String),(String,String))

Works fine. Next i have some more functions, that basicly make a virtual board with coordinates. If it's empty it will just return spaces in the strings, if not it will return the info i took up there without the first pair of strings. That pair represents the coordinates and i don't need that anymore

So that function looks like this:

vboard :: [Element] -> [[(String,String, (String,String))]]

if i print this out, this is just fine.

Now this is the part where it gets messy. I want to make a new board based on the vboard result. So i have two functions. First one is transform

transform :: (String,String,(String,String)) -> [String]
transform (p,o,(pl,ml)) | (p,o,(pl,ml)) == ("A","N",("","")) = ["aaa","aaa","aaa"]
transform (p,o,(pl,ml)) | (p,o,(pl,ml)) == ("B","N",("","")) = ["bbb","bbb","bbb"]
transform (p,o,(pl,ml)) | (p,o,(pl,ml)) == ("C","N",("","")) = ["ccc","ccc","ccc"]

As you may see, this is just for a single element. To use this i implement another function.

final :: [[(String,String,(String,String))]] -> [[[String]]]
final l = map (map (transform)) l

Ok so if i had a this for a vboard "results", a board with two lines it would look something like this right?

[[("A","N",("","")),("A","N",("",""))],
 [("B","N",("","")),("C","N",("",""))]]

then if i apply final function to this result i want the outcome to be

[[["aaa","aaa","aaa"],["aaa","aaa","aaa"]]
 [["bbb","bbb","bbb"],["ccc","ccc","ccc"]]]

but when i run this in ghci it give me an error

Invalid type signature final [[(String,String,(String,String))]] -> [[[String]]]
Should be of form <variable> :: <type> 

i am new to haskell(and english isn't my first language so i don't understand some more technical stuff), so can you explain what this error means and how should i fix it?

Regards

EDIT: You can have a look in the full code in here

http://paste2.org/pms66kdm

it has different names on the functions, but you can spot them easly.

7
  • It might be a problem with your definition of transform. If you're using guards, you don't have to retype the transform (p,o,(pl,ml)) part repeatedly, just line up your guards (|) on following lines.
    – bheklilr
    Dec 18, 2013 at 21:37
  • If I do > type Funky = (String,String,(String,String)), > let transform :: Funky -> [String]; transform = undefined, > let final :: [[Funky]] -> [[[String]]]; final = map (map transform) it type checks for me in GHC
    – bheklilr
    Dec 18, 2013 at 21:39
  • Give me a sec to try it ill give you the result :) Thanks for your time to help :)
    – Pedro Lino
    Dec 18, 2013 at 21:43
  • If you need some help reformatting your guards, look at Learn You A Haskell's examples.
    – bheklilr
    Dec 18, 2013 at 21:47
  • Nop, it still gives me the same error but now instead of [[(String,String...etc]] it says [[Funky]]
    – Pedro Lino
    Dec 18, 2013 at 21:47

2 Answers 2

1

Here is the problem-

drawfinal2 l :: [[Funky]] -> [[[String]]]

You have an extra l in the definition. If you remove it, the problem should go away.

3
  • Ok nice eye :D Now i have a new problem. How can i change the transform function so it only needs the first two parameters? I just want to take it if p and the o matches and ignore the rest.
    – Pedro Lino
    Dec 18, 2013 at 22:29
  • transform ("A","N",_) = ["aaa","aaa","aaa"].... The "_" matches anything, and you don't need a guard here, by typing in the strings you enforce that only that case will be pattern matched in this case.
    – jamshidh
    Dec 18, 2013 at 23:16
  • Hi there jamshidh, the problem with that is that i have to do one by one. can you come in the chat so i can explain in more detail? chat.stackoverflow.com/rooms/43461/…
    – Pedro Lino
    Dec 18, 2013 at 23:26
0

To debug type issues like these, I try to comment out the offending type declaration (in your case final :: [[... and compile with -Wall to see what type GHC infers by itself - if it at all compiles.

GHC gives you the awesome tool of type inference, it's worth using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.