I need to describe in Standard-ML a language made of properties and values. My property system is made of properties which can have values, like for example:
color: red | yellow | blue | transparent
align: left | center | right
bgcolor: red | yellow | blue | transparent
I created this sml file which tries to describe these properties:
datatype colorvalue = Transparent
| Yellow
| Blue
| Red
datatype bgcolorvalue = Transparent
| Yellow
| Blue
| Red
datatype alignvalue = Left
| Center
| Right
(* Generic property: it can be any of the above *)
datatype property = Color of colorvalue
| BgColor of bgcolorvalue
| Align of alignvalue
(* Some values *)
val prop1: property = Color Transparent
val prop2: property = BgColor Transparent
When I compile this in MoscowML I get:
,File "c:\Users\myuser\documents\myproj\property.sml", line 21, characters 31-42:
! val prop1: property = Color Transparent
! ^^^^^^^^^^^
! Type clash: expression of type
! bgcolorvalue
! cannot have type
! colorvalue
My guess
So I think that the problem is that color and bgcolor share a common property value: transparent which reflects in datatypes colorvalue and bgcolorvalue to share constructor Transparent. Actually they share all values, thus all constructors.
- Is it the reason for this failure?
- In any case, what should I do to describe my system?