2 ------------------------------------------------------------------
3 -- A primop-table mangling program --
4 ------------------------------------------------------------------
14 import System ( getArgs )
15 import Maybe ( catMaybes )
18 main = getArgs >>= \args ->
19 if length args /= 1 || head args `notElem` known_args
20 then error ("usage: genprimopcode command < primops.txt > ...\n"
21 ++ " where command is one of\n"
22 ++ unlines (map (" "++) known_args)
27 Left err -> error ("parse error at " ++ (show err))
28 Right p_o_specs@(Info _ entries)
29 -> seq (sanityTop p_o_specs) (
33 -> putStr (gen_data_decl p_o_specs)
36 -> putStr (gen_switch_from_attribs
38 "primOpHasSideEffects" p_o_specs)
41 -> putStr (gen_switch_from_attribs
43 "primOpOutOfLine" p_o_specs)
46 -> putStr (gen_switch_from_attribs
48 "commutableOp" p_o_specs)
51 -> putStr (gen_switch_from_attribs
53 "primOpNeedsWrapper" p_o_specs)
56 -> putStr (gen_switch_from_attribs
58 "primOpCanFail" p_o_specs)
61 -> putStr (gen_switch_from_attribs
63 "primOpStrictness" p_o_specs)
65 "--primop-primop-info"
66 -> putStr (gen_primop_info p_o_specs)
69 -> putStr (gen_primop_tag p_o_specs)
72 -> putStr (gen_primop_list p_o_specs)
74 "--make-haskell-wrappers"
75 -> putStr (gen_wrappers p_o_specs)
77 "--make-haskell-source"
78 -> putStr (gen_hs_source p_o_specs)
80 "--make-ext-core-source"
81 -> putStr (gen_ext_core_source entries)
84 -> putStr (gen_latex_doc p_o_specs)
86 _ -> error "Should not happen, known_args out of sync?"
89 known_args :: [String]
98 "--primop-primop-info",
101 "--make-haskell-wrappers",
102 "--make-haskell-source",
103 "--make-ext-core-source",
107 ------------------------------------------------------------------
108 -- Code generators -----------------------------------------------
109 ------------------------------------------------------------------
111 gen_hs_source :: Info -> String
112 gen_hs_source (Info defaults entries) =
113 "-----------------------------------------------------------------------------\n"
115 ++ "-- Module : GHC.Prim\n"
117 ++ "-- Maintainer : cvs-ghc@haskell.org\n"
118 ++ "-- Stability : internal\n"
119 ++ "-- Portability : non-portable (GHC extensions)\n"
121 ++ "-- GHC\'s primitive types and operations.\n"
123 ++ "-----------------------------------------------------------------------------\n"
124 ++ "module GHC.Prim (\n"
125 ++ unlines (map (("\t" ++) . hdr) entries)
127 ++ unlines (map opt defaults) ++ "-}\n"
128 ++ unlines (map ent entries) ++ "\n\n\n"
129 where opt (OptionFalse n) = n ++ " = False"
130 opt (OptionTrue n) = n ++ " = True"
131 opt (OptionString n v) = n ++ " = { " ++ v ++ "}"
133 hdr s@(Section {}) = sec s
134 hdr (PrimOpSpec { name = n }) = wrapOp n ++ ","
135 hdr (PseudoOpSpec { name = n }) = wrapOp n ++ ","
136 hdr (PrimTypeSpec { ty = TyApp n _ }) = wrapTy n ++ ","
137 hdr (PrimTypeSpec {}) = error "Illegal type spec"
139 ent (Section {}) = ""
140 ent o@(PrimOpSpec {}) = spec o
141 ent o@(PrimTypeSpec {}) = spec o
142 ent o@(PseudoOpSpec {}) = spec o
144 sec s = "\n-- * " ++ escape (title s) ++ "\n"
145 ++ (unlines $ map ("-- " ++ ) $ lines $ unlatex $ escape $ "|" ++ desc s) ++ "\n"
147 spec o = comm ++ decl
148 where decl = case o of
149 PrimOpSpec { name = n, ty = t } -> wrapOp n ++ " :: " ++ pty t
150 PseudoOpSpec { name = n, ty = t } -> wrapOp n ++ " :: " ++ pty t
151 PrimTypeSpec { ty = t } -> "data " ++ pty t
154 comm = case (desc o) of
156 d -> "\n" ++ (unlines $ map ("-- " ++ ) $ lines $ unlatex $ escape $ "|" ++ d)
158 pty (TyF t1 t2) = pbty t1 ++ " -> " ++ pty t2
161 pbty (TyApp tc ts) = tc ++ (concat (map (' ':) (map paty ts)))
162 pbty (TyUTup ts) = "(# " ++ (concat (intersperse "," (map pty ts))) ++ " #)"
166 paty t = "(" ++ pty t ++ ")"
168 wrapOp nm | isAlpha (head nm) = nm
169 | otherwise = "(" ++ nm ++ ")"
170 wrapTy nm | isAlpha (head nm) = nm
171 | otherwise = "(" ++ nm ++ ")"
172 unlatex s = case s of
173 '\\':'t':'e':'x':'t':'t':'t':'{':cs -> markup "@" "@" cs
174 '{':'\\':'t':'t':cs -> markup "@" "@" cs
175 '{':'\\':'i':'t':cs -> markup "/" "/" cs
176 c : cs -> c : unlatex cs
178 markup s t xs = s ++ mk (dropWhile isSpace xs)
180 mk ('\n':cs) = ' ' : mk cs
181 mk ('}':cs) = t ++ unlatex cs
182 mk (c:cs) = c : mk cs
183 escape = concatMap (\c -> if c `elem` special then '\\':c:[] else c:[])
184 where special = "/'`\"@<"
186 -- Generates the type environment that the stand-alone External Core tools use.
187 gen_ext_core_source :: [Entry] -> String
188 gen_ext_core_source entries =
189 "-----------------------------------------------------------------------\n"
190 ++ "-- This module is automatically generated by the GHC utility\n"
191 ++ "-- \"genprimopcode\". Do not edit!\n"
192 ++ "-----------------------------------------------------------------------\n"
193 ++ "module Language.Core.PrimEnv(primTcs, primVals, intLitTypes, ratLitTypes,"
194 ++ "\n charLitTypes, stringLitTypes) where\nimport Language.Core.Core"
195 ++ "\nimport Language.Core.Encoding\n\n"
196 ++ "primTcs :: [(Tcon, Kind)]\n"
198 ++ printList tcEnt entries
200 ++ "primVals :: [(Var, Ty)]\n"
202 ++ printList valEnt entries
204 ++ "intLitTypes :: [Ty]\n"
205 ++ "intLitTypes = [\n"
206 ++ printList tyEnt (intLitTys entries)
208 ++ "ratLitTypes :: [Ty]\n"
209 ++ "ratLitTypes = [\n"
210 ++ printList tyEnt (ratLitTys entries)
212 ++ "charLitTypes :: [Ty]\n"
213 ++ "charLitTypes = [\n"
214 ++ printList tyEnt (charLitTys entries)
216 ++ "stringLitTypes :: [Ty]\n"
217 ++ "stringLitTypes = [\n"
218 ++ printList tyEnt (stringLitTys entries)
221 where printList f = concat . intersperse ",\n" . filter (not . null) . map f
222 tcEnt (PrimTypeSpec {ty=t}) =
224 TyApp tc args -> parens tc (tcKind tc args)
225 _ -> error ("tcEnt: type in PrimTypeSpec is not a type"
226 ++ " constructor: " ++ show t)
229 -- The primops.txt.pp format doesn't have enough information in it to
230 -- print out some of the information that ext-core needs (like kinds,
231 -- and later on in this code, module names) so we special-case. An
232 -- alternative would be to refer to things indirectly and hard-wire
233 -- certain things (e.g., the kind of the Any constructor, here) into
234 -- ext-core's Prims module again.
235 tcKind "Any" _ = "Klifted"
236 tcKind tc [] | last tc == '#' = "Kunlifted"
237 tcKind tc [] | otherwise = "Klifted"
238 -- assumes that all type arguments are lifted (are they?)
239 tcKind tc (v:as) = "(Karrow Klifted " ++ tcKind tc as
241 valEnt (PseudoOpSpec {name=n, ty=t}) = valEntry n t
242 valEnt (PrimOpSpec {name=n, ty=t}) = valEntry n t
244 valEntry name ty = parens name (mkForallTy (freeTvars ty) (pty ty))
245 where pty (TyF t1 t2) = mkFunTy (pty t1) (pty t2)
246 pty (TyApp tc ts) = mkTconApp (mkTcon tc) (map pty ts)
247 pty (TyUTup ts) = mkUtupleTy (map pty ts)
248 pty (TyVar tv) = paren $ "Tvar \"" ++ tv ++ "\""
250 mkFunTy s1 s2 = "Tapp " ++ (paren ("Tapp (Tcon tcArrow)"
253 mkTconApp tc args = foldl tapp tc args
254 mkTcon tc = paren $ "Tcon " ++ paren (qualify True tc)
255 mkUtupleTy args = foldl tapp (tcUTuple (length args)) args
257 mkForallTy vs t = foldr
258 (\ v s -> "Tforall " ++
259 (paren (quot v ++ ", " ++ vKind v)) ++ " "
266 freeTvars (TyF t1 t2) = freeTvars t1 `union` freeTvars t2
267 freeTvars (TyApp _ tys) = freeTvarss tys
268 freeTvars (TyVar v) = [v]
269 freeTvars (TyUTup tys) = freeTvarss tys
270 freeTvarss = nub . concatMap freeTvars
272 tapp s nextArg = paren $ "Tapp " ++ s ++ " " ++ paren nextArg
273 tcUTuple n = paren $ "Tcon " ++ paren (qualify False $ "Z"
276 tyEnt (PrimTypeSpec {ty=(TyApp tc args)}) = " " ++ paren ("Tcon " ++
277 (paren (qualify True tc)))
280 -- more hacks. might be better to do this on the ext-core side,
281 -- as per earlier comment
282 qualify _ tc | tc == "ByteArr#" = qualify True "ByteArray#"
283 qualify _ tc | tc == "MutArr#" = qualify True "MutableArray#"
284 qualify _ tc | tc == "MutByteArr#" =
285 qualify True "MutableByteArray#"
286 qualify _ tc | tc == "Bool" = "Just boolMname" ++ ", "
288 qualify _ tc | tc == "()" = "Just baseMname" ++ ", "
290 qualify enc tc = "Just primMname" ++ ", " ++ (ze enc tc)
291 ze enc tc = (if enc then "zEncodeString " else "")
292 ++ "\"" ++ tc ++ "\""
294 intLitTys = prefixes ["Int", "Word", "Addr", "Char"]
295 ratLitTys = prefixes ["Float", "Double"]
296 charLitTys = prefixes ["Char"]
297 stringLitTys = prefixes ["Addr"]
298 prefixes ps = filter (\ t ->
300 (PrimTypeSpec {ty=(TyApp tc args)}) ->
301 any (\ p -> p `isPrefixOf` tc) ps
304 parens n ty = " (zEncodeString \"" ++ n ++ "\", " ++ ty ++ ")"
305 paren s = "(" ++ s ++ ")"
306 quot s = "\"" ++ s ++ "\""
308 gen_latex_doc :: Info -> String
309 gen_latex_doc (Info defaults entries)
310 = "\\primopdefaults{"
311 ++ mk_options defaults
313 ++ (concat (map mk_entry entries))
314 where mk_entry (PrimOpSpec {cons=constr,name=n,ty=t,cat=c,desc=d,opts=o}) =
316 ++ latex_encode constr ++ "}{"
317 ++ latex_encode n ++ "}{"
318 ++ latex_encode (zencode n) ++ "}{"
319 ++ latex_encode (show c) ++ "}{"
320 ++ latex_encode (mk_source_ty t) ++ "}{"
321 ++ latex_encode (mk_core_ty t) ++ "}{"
325 mk_entry (Section {title=ti,desc=d}) =
327 ++ latex_encode ti ++ "}{"
329 mk_entry (PrimTypeSpec {ty=t,desc=d,opts=o}) =
331 ++ latex_encode (mk_source_ty t) ++ "}{"
332 ++ latex_encode (mk_core_ty t) ++ "}{"
336 mk_entry (PseudoOpSpec {name=n,ty=t,desc=d,opts=o}) =
338 ++ latex_encode (zencode n) ++ "}{"
339 ++ latex_encode (mk_source_ty t) ++ "}{"
340 ++ latex_encode (mk_core_ty t) ++ "}{"
344 mk_source_ty typ = pty typ
345 where pty (TyF t1 t2) = pbty t1 ++ " -> " ++ pty t2
347 pbty (TyApp tc ts) = tc ++ (concat (map (' ':) (map paty ts)))
348 pbty (TyUTup ts) = "(# " ++ (concat (intersperse "," (map pty ts))) ++ " #)"
351 paty t = "(" ++ pty t ++ ")"
353 mk_core_ty typ = foralls ++ (pty typ)
354 where pty (TyF t1 t2) = pbty t1 ++ " -> " ++ pty t2
356 pbty (TyApp tc ts) = (zencode tc) ++ (concat (map (' ':) (map paty ts)))
357 pbty (TyUTup ts) = (zencode (utuplenm (length ts))) ++ (concat ((map (' ':) (map paty ts))))
359 paty (TyVar tv) = zencode tv
360 paty (TyApp tc []) = zencode tc
361 paty t = "(" ++ pty t ++ ")"
363 utuplenm n = "(#" ++ (replicate (n-1) ',') ++ "#)"
364 foralls = if tvars == [] then "" else "%forall " ++ (tbinds tvars)
367 tbinds ("o":tbs) = "(o::?) " ++ (tbinds tbs)
368 tbinds (tv:tbs) = tv ++ " " ++ (tbinds tbs)
369 tvars_of (TyF t1 t2) = tvars_of t1 `union` tvars_of t2
370 tvars_of (TyApp _ ts) = foldl union [] (map tvars_of ts)
371 tvars_of (TyUTup ts) = foldr union [] (map tvars_of ts)
372 tvars_of (TyVar tv) = [tv]
376 ++ mk_has_side_effects o ++ "}{"
377 ++ mk_out_of_line o ++ "}{"
378 ++ mk_commutable o ++ "}{"
379 ++ mk_needs_wrapper o ++ "}{"
380 ++ mk_can_fail o ++ "}{"
381 ++ latex_encode (mk_strictness o) ++ "}{"
384 mk_has_side_effects o = mk_bool_opt o "has_side_effects" "Has side effects." "Has no side effects."
385 mk_out_of_line o = mk_bool_opt o "out_of_line" "Implemented out of line." "Implemented in line."
386 mk_commutable o = mk_bool_opt o "commutable" "Commutable." "Not commutable."
387 mk_needs_wrapper o = mk_bool_opt o "needs_wrapper" "Needs wrapper." "Needs no wrapper."
388 mk_can_fail o = mk_bool_opt o "can_fail" "Can fail." "Cannot fail."
390 mk_bool_opt o opt_name if_true if_false =
391 case lookup_attrib opt_name o of
392 Just (OptionTrue _) -> if_true
393 Just (OptionFalse _) -> if_false
394 Just (OptionString _ _) -> error "String value for boolean option"
398 case lookup_attrib "strictness" o of
399 Just (OptionString _ s) -> s -- for now
400 Just _ -> error "Boolean value for strictness"
404 case maybe_tuple xs of
405 Just n -> n -- Tuples go to Z2T etc
406 Nothing -> concat (map encode_ch xs)
408 maybe_tuple "(# #)" = Just("Z1H")
409 maybe_tuple ('(' : '#' : cs) = case count_commas (0::Int) cs of
410 (n, '#' : ')' : _) -> Just ('Z' : shows (n+1) "H")
412 maybe_tuple "()" = Just("Z0T")
413 maybe_tuple ('(' : cs) = case count_commas (0::Int) cs of
414 (n, ')' : _) -> Just ('Z' : shows (n+1) "T")
416 maybe_tuple _ = Nothing
418 count_commas :: Int -> String -> (Int, String)
419 count_commas n (',' : cs) = count_commas (n+1) cs
420 count_commas n cs = (n,cs)
422 unencodedChar :: Char -> Bool -- True for chars that don't need encoding
423 unencodedChar 'Z' = False
424 unencodedChar 'z' = False
425 unencodedChar c = isAlphaNum c
427 encode_ch :: Char -> String
428 encode_ch c | unencodedChar c = [c] -- Common case first
431 encode_ch '(' = "ZL" -- Needed for things like (,), and (->)
432 encode_ch ')' = "ZR" -- For symmetry with (
452 encode_ch '\'' = "zq"
453 encode_ch '\\' = "zr"
458 encode_ch c = 'z' : shows (ord c) "U"
461 latex_encode (c:cs) | c `elem` "#$%&_^{}" = "\\" ++ c:(latex_encode cs)
462 latex_encode ('~':cs) = "\\verb!~!" ++ (latex_encode cs)
463 latex_encode ('\\':cs) = "$\\backslash$" ++ (latex_encode cs)
464 latex_encode (c:cs) = c:(latex_encode cs)
466 gen_wrappers :: Info -> String
467 gen_wrappers (Info _ entries)
468 = "{-# LANGUAGE NoImplicitPrelude #-}\n"
469 -- Dependencies on Prelude must be explicit in libraries/base, but we
470 -- don't need the Prelude here so we add NoImplicitPrelude.
471 ++ "module GHC.PrimopWrappers where\n"
472 ++ "import qualified GHC.Prim\n"
473 ++ unlines (map f (filter (not.dodgy) (filter is_primop entries)))
475 f spec = let args = map (\n -> "a" ++ show n) [1 .. arity (ty spec)]
476 src_name = wrap (name spec)
477 in "{-# NOINLINE " ++ src_name ++ " #-}\n" ++
478 src_name ++ " " ++ unwords args
479 ++ " = (GHC.Prim." ++ name spec ++ ") " ++ unwords args
480 wrap nm | isLower (head nm) = nm
481 | otherwise = "(" ++ nm ++ ")"
485 [-- C code generator can't handle these
488 -- not interested in parallel support
489 "par#", "parGlobal#", "parLocal#", "parAt#",
490 "parAtAbs#", "parAtRel#", "parAtForNow#"
493 gen_primop_list :: Info -> String
494 gen_primop_list (Info _ entries)
496 [ " [" ++ cons first ]
498 map (\p -> " , " ++ cons p) rest
501 ) where (first:rest) = filter is_primop entries
503 gen_primop_tag :: Info -> String
504 gen_primop_tag (Info _ entries)
505 = unlines (max_def_type : max_def :
506 tagOf_type : zipWith f primop_entries [1 :: Int ..])
508 primop_entries = filter is_primop entries
509 tagOf_type = "tagOf_PrimOp :: PrimOp -> FastInt"
510 f i n = "tagOf_PrimOp " ++ cons i ++ " = _ILIT(" ++ show n ++ ")"
511 max_def_type = "maxPrimOpTag :: Int"
512 max_def = "maxPrimOpTag = " ++ show (length primop_entries)
514 gen_data_decl :: Info -> String
515 gen_data_decl (Info _ entries)
516 = let conss = map cons (filter is_primop entries)
517 in "data PrimOp\n = " ++ head conss ++ "\n"
518 ++ unlines (map (" | "++) (tail conss))
520 gen_switch_from_attribs :: String -> String -> Info -> String
521 gen_switch_from_attribs attrib_name fn_name (Info defaults entries)
522 = let defv = lookup_attrib attrib_name defaults
523 alternatives = catMaybes (map mkAlt (filter is_primop entries))
525 getAltRhs (OptionFalse _) = "False"
526 getAltRhs (OptionTrue _) = "True"
527 getAltRhs (OptionString _ s) = s
530 = case lookup_attrib attrib_name (opts po) of
532 Just xx -> Just (fn_name ++ " " ++ cons po ++ " = " ++ getAltRhs xx)
536 Nothing -> error ("gen_switch_from: " ++ attrib_name)
538 -> unlines alternatives
539 ++ fn_name ++ " _ = " ++ getAltRhs xx ++ "\n"
541 ------------------------------------------------------------------
542 -- Create PrimOpInfo text from PrimOpSpecs -----------------------
543 ------------------------------------------------------------------
545 gen_primop_info :: Info -> String
546 gen_primop_info (Info _ entries)
547 = unlines (map mkPOItext (filter is_primop entries))
549 mkPOItext :: Entry -> String
550 mkPOItext i = mkPOI_LHS_text i ++ mkPOI_RHS_text i
552 mkPOI_LHS_text :: Entry -> String
554 = "primOpInfo " ++ cons i ++ " = "
556 mkPOI_RHS_text :: Entry -> String
562 -> "mkCompare " ++ sl_name i ++ ppType t1
563 _ -> error "Type error in comparison op"
567 -> "mkMonadic " ++ sl_name i ++ ppType t1
568 _ -> error "Type error in monadic op"
572 -> "mkDyadic " ++ sl_name i ++ ppType t1
573 _ -> error "Type error in dyadic op"
575 -> let (argTys, resTy) = flatTys (ty i)
576 tvs = nub (tvsIn (ty i))
578 "mkGenPrimOp " ++ sl_name i ++ " "
579 ++ listify (map ppTyVar tvs) ++ " "
580 ++ listify (map ppType argTys) ++ " "
581 ++ "(" ++ ppType resTy ++ ")"
583 sl_name :: Entry -> String
584 sl_name i = "(fsLit \"" ++ name i ++ "\") "
586 ppTyVar :: String -> String
587 ppTyVar "a" = "alphaTyVar"
588 ppTyVar "b" = "betaTyVar"
589 ppTyVar "c" = "gammaTyVar"
590 ppTyVar "s" = "deltaTyVar"
591 ppTyVar "o" = "openAlphaTyVar"
592 ppTyVar _ = error "Unknown type var"
594 ppType :: Ty -> String
595 ppType (TyApp "Bool" []) = "boolTy"
597 ppType (TyApp "Int#" []) = "intPrimTy"
598 ppType (TyApp "Int32#" []) = "int32PrimTy"
599 ppType (TyApp "Int64#" []) = "int64PrimTy"
600 ppType (TyApp "Char#" []) = "charPrimTy"
601 ppType (TyApp "Word#" []) = "wordPrimTy"
602 ppType (TyApp "Word32#" []) = "word32PrimTy"
603 ppType (TyApp "Word64#" []) = "word64PrimTy"
604 ppType (TyApp "Addr#" []) = "addrPrimTy"
605 ppType (TyApp "Float#" []) = "floatPrimTy"
606 ppType (TyApp "Double#" []) = "doublePrimTy"
607 ppType (TyApp "ByteArr#" []) = "byteArrayPrimTy"
608 ppType (TyApp "RealWorld" []) = "realWorldTy"
609 ppType (TyApp "ThreadId#" []) = "threadIdPrimTy"
610 ppType (TyApp "ForeignObj#" []) = "foreignObjPrimTy"
611 ppType (TyApp "BCO#" []) = "bcoPrimTy"
612 ppType (TyApp "()" []) = "unitTy" -- unitTy is TysWiredIn's name for ()
614 ppType (TyVar "a") = "alphaTy"
615 ppType (TyVar "b") = "betaTy"
616 ppType (TyVar "c") = "gammaTy"
617 ppType (TyVar "s") = "deltaTy"
618 ppType (TyVar "o") = "openAlphaTy"
619 ppType (TyApp "State#" [x]) = "mkStatePrimTy " ++ ppType x
620 ppType (TyApp "MutVar#" [x,y]) = "mkMutVarPrimTy " ++ ppType x
622 ppType (TyApp "MutArr#" [x,y]) = "mkMutableArrayPrimTy " ++ ppType x
625 ppType (TyApp "MutByteArr#" [x]) = "mkMutableByteArrayPrimTy "
628 ppType (TyApp "Array#" [x]) = "mkArrayPrimTy " ++ ppType x
631 ppType (TyApp "Weak#" [x]) = "mkWeakPrimTy " ++ ppType x
632 ppType (TyApp "StablePtr#" [x]) = "mkStablePtrPrimTy " ++ ppType x
633 ppType (TyApp "StableName#" [x]) = "mkStableNamePrimTy " ++ ppType x
635 ppType (TyApp "MVar#" [x,y]) = "mkMVarPrimTy " ++ ppType x
637 ppType (TyApp "TVar#" [x,y]) = "mkTVarPrimTy " ++ ppType x
639 ppType (TyUTup ts) = "(mkTupleTy Unboxed " ++ show (length ts)
641 ++ listify (map ppType ts) ++ ")"
643 ppType (TyF s d) = "(mkFunTy (" ++ ppType s ++ ") (" ++ ppType d ++ "))"
646 = error ("ppType: can't handle: " ++ show other ++ "\n")
648 listify :: [String] -> String
649 listify ss = "[" ++ concat (intersperse ", " ss) ++ "]"
651 flatTys :: Ty -> ([Ty],Ty)
652 flatTys (TyF t1 t2) = case flatTys t2 of (ts,t) -> (t1:ts,t)
653 flatTys other = ([],other)
655 tvsIn :: Ty -> [TyVar]
656 tvsIn (TyF t1 t2) = tvsIn t1 ++ tvsIn t2
657 tvsIn (TyApp _ tys) = concatMap tvsIn tys
658 tvsIn (TyVar tv) = [tv]
659 tvsIn (TyUTup tys) = concatMap tvsIn tys
662 arity = length . fst . flatTys