1 /**********************************************************************
4 * Convert Types to Contexts *
7 **********************************************************************/
12 #include "constants.h"
18 static void is_context_format PROTO((ttype)); /* forward */
21 partain: see also the comment by "decl" in hsparser.y.
23 Here, we've been given a type that must be of the form
24 "C a" or "(C1 a, C2 a, ...)" [otherwise an error]
40 /* returning the list is OK, but ensure items are right format */
43 if (tlist(args) == lnil)
44 hsperror ("type2context: () found instead of a context");
46 while (tlist(args) != lnil)
48 is_context_format(lhd(args));
52 return(gttuple(t)); /* args */
56 tycon_name = gtypeid(t);
58 /* just a class name ":: C =>" */
59 if (tlist(gtypel(t)) == lnil)
60 return (mklcons(t, Lnil));
62 /* should be just: ":: C a =>" */
65 first_arg = (ttype) lhd(gtypel(t));
66 rest_args = ltl(gtypel(t)); /* should be nil */
68 if (tlist(rest_args) != lnil)
69 hsperror ("type2context: too many variables after class name");
71 switch (tttype(first_arg))
73 case namedtvar: /* ToDo: right? */
74 return (mklcons(t, Lnil));
78 hsperror ("type2context: something wrong with variable after class name");
84 hsperror ("type2context: unexpected namedtvar found in a context");
87 hsperror ("type2context: list constructor found in a context");
90 hsperror ("type2context: arrow (->) constructor found in a context");
93 hsperror ("type2context: unexpected context-thing found in a context");
96 hsperror ("type2context: totally unexpected input");
98 abort(); /* should never get here! */
102 /* is_context_format is the same as "type2context" except that it just performs checking */
103 /* ttype is either "tycon" [class] or "tycon (named)tvar" [class var] */
116 tycon_name = gtypeid(t);
118 /* just a class name ":: C =>" */
119 if (tlist(gtypel(t)) == lnil)
120 hsperror("is_context_format: variable missing after class name");
122 /* should be just: ":: C a =>" */
125 first_arg = (ttype) lhd(gtypel(t));
126 rest_args = ltl(gtypel(t)); /* should be nil */
127 if (tlist(rest_args) != lnil)
128 hsperror ("is_context_format: too many variables after class name");
130 switch (tttype(first_arg))
132 case namedtvar: /* ToDo: right? */
133 /* everything is cool; will fall off the end */
136 hsperror ("is_context_format: something wrong with variable after class name");
142 hsperror ("is_context_format: tuple found in a context");
145 hsperror ("is_context_format: unexpected namedtvar found in a context");
148 hsperror ("is_context_format: list constructor found in a context");
151 hsperror ("is_context_format: arrow (->) constructor found in a context");
154 hsperror ("is_context_format: unexpected context-thing found in a context");
157 hsperror ("is_context_format: totally unexpected input");