1 /**********************************************************************
4 * Convert Types to Contexts *
7 **********************************************************************/
12 #include "constants.h"
15 static void is_context_format PROTO((ttype, int)); /* forward */
18 partain: see also the comment by "decl" in hsparser.y.
20 Here, we've been given a type that must be of the form
21 "C a" or "(C1 a, C2 a, ...)" [otherwise an error]
35 /* returning the list is OK, but ensure items are right format */
38 if (tlist(args) == lnil)
39 hsperror ("type2context: () found instead of a context");
41 while (tlist(args) != lnil)
43 is_context_format(lhd(args), 0);
47 return(gttuple(t)); /* args */
52 /* a single item, ensure correct format */
53 is_context_format(t, 0);
57 hsperror ("type2context: unexpected namedtvar found in a context");
60 hsperror ("type2context: list constructor found in a context");
63 hsperror ("type2context: arrow (->) constructor found in a context");
66 hsperror ("type2context: unexpected context-thing found in a context");
69 hsperror ("type2context: totally unexpected input");
71 abort(); /* should never get here! */
75 /* is_context_format is the same as "type2context" except that it just performs checking */
76 /* ttype is either "tycon" [class] or "tycon (named)tvar" [class var] */
79 is_context_format(t, tyvars)
89 /* should be just: ":: C a =>" */
92 hsperror("is_context_format: variable missing after class name");
95 hsperror ("is_context_format: too many variables after class name");
97 /* tyvars == 1; everything is cool */
101 if (tttype(gtarg(t)) != namedtvar)
102 hsperror ("is_context_format: something wrong with variable after class name");
104 is_context_format(gtapp(t), tyvars+1);
108 hsperror ("is_context_format: tuple found in a context");
111 hsperror ("is_context_format: unexpected namedtvar found in a context");
114 hsperror ("is_context_format: list constructor found in a context");
117 hsperror ("is_context_format: arrow (->) constructor found in a context");
120 hsperror ("is_context_format: unexpected context-thing found in a context");
123 hsperror ("is_context_format: totally unexpected input");