difference between $$ and $

Skip to first unread message

Ilya Kudryavtsev

Nov 20, 2023, 5:06:38 PM11/20/23
to MiniZinc
Hi MiniZinc Team!

What is the difference between $$V and $V? 

I can see that the difference exists, but it's unclear for me. 

For example, 

function var $V: at1(array[$$IDX1] of var $V: xs, var $$IDX1: row_idx) = xs[row_idx];
function var $$V: at2(array[$$IDX1] of var $$V: xs, var $$IDX1: row_idx) = xs[row_idx];

array[1..2] of bool: a;

then at1(a, 1) would be treated by MiniZinc as var int, but at2(a, 1) - as var bool. 


Jip Dekker

Nov 20, 2023, 6:10:41 PM11/20/23
to MiniZinc
The generics implemented in MiniZinc are undocumented and maybe more intended for internal use.

The number of $ does indeed have a big difference. A type variable with a single $, e.g., $T, can take any type including int, enums, records, strings, etc. A type variable with two $, e.g. $$T, can take any enumerable type. So it is limited to enums, integers, and Boolean values.

Note that other modifiers ("var", "opt", "set of", etc.) can be used to further restrict the types that a type variable can take. For example, "set of $T", can only be float, int, or enum, as no other set types exist in MiniZinc.

Ilya Kudryavtsev

Nov 22, 2023, 3:09:12 AM11/22/23
to MiniZinc
Thanks a lot, Jip! Now it's much clearer. 

But I still need some clarification. Given my example, both $$V and $V could represent bools, so why did MiniZinc deduce different return types? 

I understand that generics were introduced for internal use, but I want to mention that it's a great feature! And it could be very useful for code generators!

Reply all
Reply to author
0 new messages