I have two questions about Haskell type expression:
Question 1 -
I would like to declare a type NODE
data NODE = Node String ATTR
and a type ATTR contains 3 sub-type as follow:
Source Bool
Target Bool
Ghost Int
data ATTR = Source Bool | Target Bool | Ghost Bool
But the above declaration does not satisfy the requirement that ATTR can contain whatever the combination of sub-types such as:
- ATTR can contain Source Bool and Target Bool at once
- ATTR can contain Source Bool, Target Bool and Ghost Int at once
- ATTR can even be empty (contain nothing)
Question 2 -
I would like to declare a type GRAPH, in which a graph can contain 1 or many Statements (STMTS) or contain no Statement if the graph is empty. So I declare as follow:
data GRAPH = Graph String STMTS
data STMTS = STMT | STMTS
But again, as you see the recursive data type STMTS will repeat infinitively.