/* Type representation data structure for PCAT.
   (Includes support for reals and records.)  */

typedef struct TyperepS *Typerep;
typedef struct ProductS *Product;

struct TyperepS {
  enum {Base = 0, Array, Procedure, Record} kind;  /* type operator */
  union {
    struct {       /* for Base types: */
      char *name;  /*   type name */
    } base;
    struct {      /* for Array types: */
      Typerep etype; /*   element type */
    } array;
    struct {      /* for Procedure types: */
      Typerep rtype; /*   return type */
      Product args; /*   argument list */
    } proc;
    struct {      /* for Record types: */
      Product fields;  /* record fields in name-sorted order */
    } record;

  } u;
};

struct ProductS {      /* labelled list of types */
  char *name;		/* element name */
  Typerep type;		/* element type */
  Product link;		/* next element of product */
};

/* Constructors */			
Typerep    mk_BaseTyperep(char *name);
Typerep    mk_ArrayTyperep(Typerep etype);
Typerep    mk_ProcTyperep(Typerep rtype,Product args);
Typerep    mk_RecordTyperep(Product fields);
Product mk_Product(char *name, Typerep type, Product link);

/* Declare the built-in types. */
extern Typerep void_type;
extern Typerep int_type;
extern Typerep bool_type;
extern Typerep string_type;
extern Typerep real_type;
extern Typerep nil_type;  /* a polymorphic record type */

/* Handy for printing error messages; debugging. */
void	printtype(Typerep, FILE * fp);


