ExpandCollapsePrev Next Index

+ 6.1 Exporting Structs

It is possible to export a struct. You can do this:

  export struct X { 
    export fun f(b:int) => self.a + b;

This causes the interface file to contain

  cstruct X { a:int; z:float;};

which provides access to both the fields and the standard constructor:


This is a C binding to the struct definee in the original file, which is exported with a typedef.

Note that the function {f} has to be separately exported because functions nested in structs are just sugar for a function, in the example:

  fun f(self:X) (b:int) => self.a + b;