Pelin
Pelin

Reputation: 127

What is wrong with my haskell general tree?

Here is my code and there are so many things wrong about it that i can't see. What is the problem? or what "are" the problems?? I get these errors for several lines:

Upvotes: 0

Views: 114

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476503

The problem is that if you describe a list [], you do this between square brackets separated with commas, like [1,4,2,5]. Not between round brackets: that is a tuple.

tree :: NBaum String
tree  = NKnoten "Sonne" [
    NKnoten "Erde"  [NBlatt "MOND"],
    NBlatt "Merkur",
    NBlatt "Venus",

    NKnoten "MARS" [
        NBlatt "PHOBOS",  
        NBlatt "DEIMOS" 
    ],      
    NKnoten "JUPITER" [
        NBlatt "Io",
        NBlatt "EUROPA",
        NBlatt "GANYMED",
        NBlatt "KALLISTO"
    ]
]

Furthermore - as is highlighted in the code fragment - you (probably accidentally) - wrote the type name (NBaum) instead of constructor name (NKnoten) at the first object (the "Sonne").

Upvotes: 4

Related Questions