Author Topic: Generics of Cyclone  (Read 7443 times)

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Generics of Cyclone
« 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.