Stream: Beginner Questions

Topic: Define a datatype from a given scope


view this post on Zulip Hongjian Jiang (Oct 25 2023 at 08:10):

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?

view this post on Zulip Lukas Stevens (Oct 25 2023 at 08:51):

It is not really clear what you want to do exactly. Can you elaborate?

view this post on Zulip Hongjian Jiang (Oct 25 2023 at 08:58):

For example, I just want the value of 'a to be a or b, not arbitrary value.

view this post on Zulip Lukas Stevens (Oct 25 2023 at 09:06):

You could do: datatype a_or_b = A | B and then you can use a_or_b rexp

view this post on Zulip Lukas Stevens (Oct 25 2023 at 09:07):

Or more advanced: typedef a_or_b = "{CHR ''a'', CHR ''b''}" by auto. However, dealing with typedefs can be quite annoying.

view this post on Zulip Lukas Stevens (Oct 25 2023 at 09:08):

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