1.26. Generic modules

It is also possible specify type arguments for a module. The effect is simply that all the entities declared in the module are parameterised by the type parameter.

Because of this, you can open a generic module, but you must do so without specifying any type arguments.

When you use a qualified name, Felix concatenates all the arguments and applies them to the last component.

Note this excludes parent functions, since the type arguments of the parent of a function are fully determined by its child.

Start C++ section to tut/examples/tut135g.flx[1 /1 ]
     1: include "std";
     2: 
     3: module X[t] {
     4:   fun f[k]: t * k  -> t = "1";
     5:   fun cmp: t * t -> bool = "1";
     6:   fun mk: 1 -> t = "1";
     7:   fun subscript: t * t -> t = "2";
     8: }
     9: 
    10: // both args explicit
    11: var a1 = X[int,long]::f(1,1L);
    12: var a2 = X[int]::f[long](1,1L);
    13: var a3 = X::f[int,long](1,1L);
    14: 
    15: // first arg explicit
    16: var a4 = X::f[int](1,1L);
    17: var a5 = X[int]::f(1,1L);
    18: 
    19: // full deduction
    20: var a6 = X::f(1,1L);
    21: 
    22: // using unqualified names
    23: open X;
    24: var a7 = f[int,long](1,1L);
    25: var a8 = f[int](1,1L);
    26: var a9 = f(1,1L);
    27: 
    28: print a1;
    29: print a2;
    30: print a3;
    31: print a4;
    32: print a5;
    33: print a6;
    34: print a7;
    35: print a8;
    36: print a9;
    37: 
    38: print (1).[2];
    39: 
    40: var x = mk[int]();
    41: var y = mk[int]();
    42: if cmp(x,y) do print "YES"; endl; else print "NO"; endl; done;
    43: 
End C++ section to tut/examples/tut135g.flx[1]