1 /**********************************************************************
4 * Convert Types to Contexts *
7 **********************************************************************/
12 #include "constants.h"
16 partain: see also the comment by "decl" in hsparser.y.
18 Here, we've been given a type that must be of the form
19 "C a" or "(C1 a, C2 a, ...)" [otherwise an error]
33 /* returning the list is OK, but ensure items are right format */
36 if (tlist(args) == lnil)
37 hsperror ("type2context: () found instead of a context");
39 while (tlist(args) != lnil)
41 is_context_format(lhd(args), 0);
45 return(gttuple(t)); /* args */
50 /* a single item, ensure correct format */
51 is_context_format(t, 0);
55 hsperror ("type2context: unexpected namedtvar found in a context");
58 hsperror ("type2context: list constructor found in a context");
61 hsperror ("type2context: arrow (->) constructor found in a context");
64 hsperror ("type2context: totally unexpected input");
66 abort(); /* should never get here! */
70 /* is_context_format is the same as "type2context" except that it just performs checking */
71 /* ttype is either "tycon" [class] or "tycon (named)tvar" [class var] */
74 is_context_format(t, tyvars)
84 /* should be just: ":: C a =>" */
87 hsperror("is_context_format: type missing after class name");
89 /* tyvars > 0; everything is cool */
93 is_context_format(gtapp(t), tyvars+1);
97 hsperror ("is_context_format: tuple found in a context");
100 hsperror ("is_context_format: unexpected namedtvar found in a context");
103 hsperror ("is_context_format: list constructor found in a context");
106 hsperror ("is_context_format: arrow (->) constructor found in a context");
108 hsperror ("is_context_format: totally unexpected input");