For the regular expression from the text-book, the normal definition will be given an alphabet {a, b}, and rexp below.
datatype (atoms: 'a) rexp =
Zero
| One
| Atom "'a"
| Plus "'a rexp" "'a rexp"
| Times "'a rexp" "'a rexp"
| Star "'a rexp"
| Inter "'a rexp" "'a rexp"
Here, the regular expressions are over arbitrary alphabets. What I want is to make atoms represent as set {a,b}.
Is that possible?
It is not really clear what you want to do exactly. Can you elaborate?
For example, I just want the value of 'a to be a or b, not arbitrary value.
You could do: datatype a_or_b = A | B
and then you can use a_or_b rexp
Or more advanced: typedef a_or_b = "{CHR ''a'', CHR ''b''}" by auto
. However, dealing with typedefs can be quite annoying.
I would recommend that you just put an assumption atoms r = {a, b}
where you need it
Last updated: Dec 21 2024 at 16:20 UTC