0
votes

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:

  • Data constructor not in scope. NBaum
  • Couldn't match expected type [NBaum [Char]]' with actual type `NBaum [Char]'
  • In the second argument of NKnoten', namely `(NBlatt "Io")'
  • In the sixth argument of `NBaum', namely

    data NBaum a = NBlatt a | NKnoten a [NBaum a]
    deriving(Eq,Show)
    
    
    tree :: NBaum String
    tree  =   
    NBaum "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" )
    
    ) 
    
1
You tell us. What is the problem? Are you getting an error? Does something not work right? Your question is very vague. Describe exactly what you're trying to do, what's actually happening, and what you tried to fix it already.Carcigenicate
I have so many of them. Therefore i thought it is weird and didn't add them in the beginning.Pelin
Always post errors you get. The less guessing we're forced to do about what your problem is, the higher chance someone will answer your question. You got lucky that an expert like Willem saw your question.Carcigenicate

1 Answers

4
votes

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").