reset password
Author Message
rabbott
Posts: 1649
Posted 17:39 Oct 29, 2019 |

As most of you have discovered, you cannot include integers as enumeration items. But you can include integers surrounded by single quotes as enumeration items.

That is, enum EnumType = {1, 2, 3} is not acceptable, but enum EnumType = {'1', '2', '3'} is.

Has anyone determined why that is the case or where that is specified?

(I looked it up, but if anyone else knows, I'll give you a chance to answer first.)

fumjum
Posts: 27
Posted 17:58 Oct 29, 2019 |

I believe it is because an enum can be identified by its elements, so if you have the elements as numbers the interpreter wouldn't be able to tell the difference between 1 being an element of the enum and a regular integer. So that's why it isn't allowed. 

Last edited by fumjum at 17:58 Oct 29, 2019.
rabbott
Posts: 1649
Posted 18:16 Oct 29, 2019 |

Good start. Now explain why it is allowed.

fumjum
Posts: 27
Posted 18:26 Oct 29, 2019 |

I couldn't find any info about why the single quotes work with integers besides in corsera where they say that MiniZinc treats anything in enums with single quotes as identifiers.

rabbott
Posts: 1649
Posted 19:33 Oct 29, 2019 |

That's actually close. But it's a bit more general than that.

Try running this.

enum 'an enum' = {'some thing', 'some other thing', 'still a third thing'};
output ["The enum 'an enum' consists of \('an enum')."];

Look at section 4.1.4.3. Identifiers.  

Last edited by rabbott at 20:10 Oct 29, 2019.