on master help sign in
style: stop using many line definition
commit564cf4ea64a21da1d45fe6bc47a5d5e1cdea6049 authorEvan Czaplicki <info@elm-lang.org> dateSat 13 Sep 2014, 10:04 (12 years ago) parenta48fdb2
1 file changed+21−10
compiler/Generate/Cases.hs+21−10
compiler/Generate/Cases.hs+21−10
@@ -65,16 +65,27 @@ isVar :: ([P.Pattern var], expr) -> Bool
6565isVar p = not (isCon p)
6666
6767match :: [String] -> [([P.CanonicalPattern], Canonical.Expr)] -> Match -> State.State Int Match
68−match [] [] def = return def
69−match [] [([],e)] Fail = return $ Other e
70−match [] [([],e)] Break = return $ Other e
71−match [] cs def = return $ Seq (map (Other . snd) cs ++ [def])
72−match vs@(v:_) cs def
73− | all isVar cs' = matchVar vs cs' def
74− | all isCon cs' = matchCon vs cs' def
75− | otherwise = matchMix vs cs' def
76− where
77− cs' = map (dealias v) cs
68+match variables cases match =
69+ case (variables, cases, match) of
70+ ([], [], _) ->
71+ return match
72+
73+ ([], [([], expr)], Fail) ->
74+ return $ Other expr
75+
76+ ([], [([], expr)], Break) ->
77+ return $ Other expr
78+
79+ ([], _, _) ->
80+ return $ Seq (map (Other . snd) cases ++ [match])
81+
82+ (var:_, _, _)
83+ | all isVar cases' -> matchVar variables cases' match
84+ | all isCon cases' -> matchCon variables cases' match
85+ | otherwise -> matchMix variables cases' match
86+ where
87+ cases' = map (dealias var) cases
88+
7889
7990dealias :: String -> ([P.CanonicalPattern], Canonical.Expr) -> ([P.CanonicalPattern], Canonical.Expr)
8091dealias _ ([], _) = noMatch "dealias"