RosettaCodeData/Task/Classes/MiniZinc/classes.minizinc

29 lines
882 B
Plaintext

% define a Rectangle "class"
var int: Rectangle(var int: width, var int: height) =
let {
var int: this;
constraint Type(this) = Rectangle; %define the "type" of the instance
%define some "instance methods"
constraint area(this) = width*height;
constraint width(this) = width;
constraint height(this) = height;
} in this;
%this enum should contain the list of class names
enum Type = {Rectangle};
function var Type: Type(var int:a);
%declare the "instance methods"
function var int: area(var int:this) = let {var int:result;} in result;
function var int: height(var int:a) = let {var int:result;} in result;
function var int: width(var int:a) = let {var int:result;} in result;
%create an instance of the "class"
var int: rect = Rectangle(3,4);
var int: area1 = area(rect);
solve satisfy;
% print the area of the rectangle
output [show(area1),"\n"];