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: unexpected context-thing found in a context");
67 hsperror ("type2context: totally unexpected input");
69 abort(); /* should never get here! */
73 /* is_context_format is the same as "type2context" except that it just performs checking */
74 /* ttype is either "tycon" [class] or "tycon (named)tvar" [class var] */
77 is_context_format(t, tyvars)
87 /* should be just: ":: C a =>" */
90 hsperror("is_context_format: type missing after class name");
92 /* tyvars > 0; everything is cool */
96 is_context_format(gtapp(t), tyvars+1);
100 hsperror ("is_context_format: tuple found in a context");
103 hsperror ("is_context_format: unexpected namedtvar found in a context");
106 hsperror ("is_context_format: list constructor found in a context");
109 hsperror ("is_context_format: arrow (->) constructor found in a context");
112 hsperror ("is_context_format: unexpected context-thing found in a context");
115 hsperror ("is_context_format: totally unexpected input");