on master help sign in
Add ability to collect App1's into a Type constructor

Useful for determining if something is a Tuple or List

commit3da8a71d0014928f19772a647de60867aeca23b4 authorEvan Czaplicki <info@elm-lang.org> dateTue 30 Jul 2013, 08:29 (13 years ago) parentdfb27a7
1 file changed+21
compiler/Type/Type.hs+21
compiler/Type/Type.hs+21
@@ -365,3 +365,24 @@ toSrcType variable = do
365365 [ "Problem converting the following type "
366366 , "from a type-checker type to a source-syntax type:"
367367 , P.render (pretty Never variable) ]
368+
369+
370+data AppStructure = List Variable | Tuple [Variable] | Other
371+
372+collectApps :: Variable -> IO AppStructure
373+collectApps variable = go [] variable
374+ where
375+ go vars variable = do
376+ desc <- UF.descriptor variable
377+ case (structure desc, vars) of
378+ (Nothing, [v]) -> case name desc of
379+ Just "_List" -> return (List v)
380+ _ -> return Other
381+ (Nothing, vs) -> case name desc of
382+ Just ctor | isTuple ctor -> return (Tuple vs)
383+ _ -> return Other
384+
385+ (Just term, vs) ->
386+ case term of
387+ App1 a b -> go (vars ++ [b]) a
388+ _ -> return Other