2.27. 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 felix section to tut/tutorial/tut-1.27-0.flx[1 /1 ]
     1: #line 3067 "./lpsrc/flx_tutorial.pak"
     2: #import <flx.flxh>
     3: 
     4: module X[t] {
     5:   fun f[k]: t * k  -> t = "1";
     6:   fun xcmp: t * t -> bool = "1";
     7:   fun mk: 1 -> t = "1";
     8:   fun subscript: t * t -> t = "2";
     9: }
    10: 
    11: // both args explicit
    12: var a1 = X[int,long]::f(1,1L);
    13: var a2 = X[int]::f[long](1,1L);
    14: var a3 = X::f[int,long](1,1L);
    15: 
    16: // first arg explicit
    17: var a4 = X::f[int](1,1L);
    18: var a5 = X[int]::f(1,1L);
    19: 
    20: // full deduction
    21: var a6 = X::f(1,1L);
    22: 
    23: // using unqualified names
    24: open X;
    25: var a7 = f[int,long](1,1L);
    26: var a8 = f[int](1,1L);
    27: var a9 = f(1,1L);
    28: 
    29: print a1;
    30: print a2;
    31: print a3;
    32: print a4;
    33: print a5;
    34: print a6;
    35: print a7;
    36: print a8;
    37: print a9;
    38: 
    39: print (1).[2];
    40: 
    41: var x = mk[int]();
    42: var y = mk[int]();
    43: if xcmp(x,y) do print "YES"; endl; else print "NO"; endl; done;
End felix section to tut/tutorial/tut-1.27-0.flx[1]
Start data section to tut/tutorial/tut-1.27-0.expect[1 /1 ]
     1: 1111111112YES
End data section to tut/tutorial/tut-1.27-0.expect[1]