C2 forum

General Category => Ideas => Topic started by: lerno on November 07, 2018, 12:57:48 AM

Title: Generics of Cyclone
Post by: lerno on November 07, 2018, 12:57:48 AM
Cyclone has generic types, called datatypes, they are used in this manner:

Code: [Select]
  datatype T {
      Integer(int);
      String(const char *@fat);
    };

    datatype T.Integer x = Integer(3);
    datatype T.String y = String("hello, world");

    void printT(datatype T@ a) {
      switch (a) {
      case &Integer(i): printf("%d",i); return;
      case &String(s): printf("%s",s); return;
      }
    }

I'm not making a proposal to add it, merely something that would be useful to discuss.