Constrained genericity or bounded quantification means
that a parametrized type or function (see parametric polymorphism)
can only be instantiated on types fulfilling some conditions,
even if those conditions are not used in that function.

Say a type is called "eatable" if you can call the function eat on it.
Write a generic type FoodBox which contains a collection of objects of
a type given as parameter, but can only be instantiated on eatable types.
The FoodBox shall not use the function eat in any way (i.e. without the explicit restriction, it could be instantiated on any type).
The specification of a type being eatable should be as generic as possible
in your language (i.e. the restrictions on the implementation of eatable types
should be as minimal as possible).
Also explain the restrictions, if any, on the implementation of eatable types,
and show at least one example of an eatable type.

 
macro Gluttony(vartype, capacity, foodlist)
'==========================================
 
typedef vartype physical
 
enum food foodlist
 
type ActualFood
  sys      name
  physical size
  physical quantity
end type
 
Class foodbox
'============
has ActualFood Item[capacity]
sys max
 
method put(sys f, physical s,q)
  max++
  Item[max]<=f,s,q
end method
 
method GetNext(ActualFood *Stuff)
  if max then
    copy @stuff,@Item[max], sizeof Item
    max--
  end if
end method
 
end class
 
Class Gourmand
'=============
physical WeightGain, SleepTime
 
method eats(ActualFood *stuff)
  WeightGain+=stuff.size*stuff.quantity*0.75
  stuff.size=0
  stuff.quantity=0
end method
 
end class
 
end macro
 
 
'IMPLEMENTATION
'==============
 
 
Gluttony (
double,100,{
oyster,trout,bloater,
chocolate,truffles,
cheesecake,cream,pudding,pie
})
 
% small  1
% medium 2
% large  3
% huge   7
 
% none    0
% single  1
% few     3
% several 7
% many    12
 
'INSTANCE
'========
 
FoodBox  Hamper
Gourmand MrG
 
'TEST
'====
 
Hamper.put food.pudding,large,several
Hamper.put food.pie,huge,few
ActualFood Course
Hamper.GetNext Course
MrG.eats Course
 
print MrG.WeightGain 'result 15.75
 