0

Manual was so kind to answer my first question, but now i'm at a lose. I want to define two types much like in propositional calculus i want to have an atomic type and one more complex type.

datatype atomicType = aa | bb | cc
datatype complexType = combine complexType complexType

Basically this plus being abled to use atomicType instances as complexType. Oc i could define another constructor "Up atomicType" for complexType, but then i don't see how i can differentiate between both types in my axioms and so on.

Mayank Patel
  • 3,868
  • 10
  • 36
  • 59
TKler
  • 135
  • 7

1 Answers1

1

The usual solution is like you suggested:

datatype complexType = combine complexType complexType |
                       atomic atomicType

The datatype command will automatically generate a lot of constants for you. One group of those are the "discriminators" of type complexType => bool. They allow you to distinguish between the cases of your type.

datatype complexType = is_combined: combine complexType complexType |
                       is_atomic: atomic atomicType

... or use the default names (described in §2.1.5 of the datatype manual).

With that, you can write down a property like

is_atomic x ==> is_combined (some_operation ...)
larsrh
  • 2,579
  • 8
  • 30
  • Doesn't this only "convert" my atomicType into a complexType via some function? – TKler Jan 08 '16 at 12:36
  • It embeds `atomicType` into `complexType` using a constructor (which is a function). Datatype inheritance isn't supported in HOL. (There is record inheritance, but that only works for product types.) – larsrh Jan 09 '16 at 13:36