Mateusz
Mateusz

Reputation: 13

Haskell List in list

Hello have a problem how to make in Haskell list of user like that:

list = [("Frank",24,[wall, door],1),("Ann",45,[window],0),
("Claudia",44,[window, bed],2), ("Pedro"77,[wall],1)]

i tried this way but it not working :

type Home = (Homename)
type Homename = String
type Person = (Name, Age, [Home], Num)
type Name = String
type Age = Integer
type Num = Integer
list :: [Person]
list = [("Frank",24,[wall, door],1),("Ann",45,[window],0),
("Claudia",44,[window, bed],2), ("Pedro",77,[wall],1)]

error: Syntax error in expression (unexpected `;', possibly due to bad layout)

Upvotes: 1

Views: 78

Answers (1)

Mahmoud S. Marwad
Mahmoud S. Marwad

Reputation: 244

the Strings must be in "string". Also, you can't name a type as Num , it's already reserved words in Prelude

you may rename it to Numb.

type Home = (Homename)
type Homename = String
type Person = (Name, Age, [Home], Numb)
type Name = String
type Age = Integer
type Numb = Integer
list :: [Person]
list = [("Frank"  ,24,["wall", "door"],1),
        ("Ann"    ,45,["window"],0),
        ("Claudia",44,["window", "bed"],2),
        ("Pedro"  ,77,["wall"],1)]

you also need to make the body of the function start after the header in all the lines.

this will give you an error as the second line starts at position 0 as the header.

list :: [Person]
list = [("Frank"  ,24,["wall", "door"],1),
("Ann"    ,45,["window"],0),
("Claudia",44,["window", "bed"],2),
("Pedro"  ,77,["wall"],1)]

Upvotes: 1

Related Questions