git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #260
commit3286eaf934622d8a12358405a78da547b9c5a817 authorPhil Freeman <paf31@cantab.net> dateFri 7 Mar 2014, 17:44 (13 years ago) parent5e2b540
2 files changed+10−2
src/Language/PureScript/Sugar/CaseDeclarations.hs+9−2 src/Language/PureScript/Sugar/Let.hs+1
src/Language/PureScript/Sugar/CaseDeclarations.hs+9−2
@@ -64,7 +64,10 @@ inSameGroup (ValueDeclaration ident1 _ _ _ _) (ValueDeclaration ident2 _ _ _ _)
6464inSameGroup _ _ = False
6565
6666toDecls :: [Declaration] -> Either String [Declaration]
67−toDecls d@[ValueDeclaration _ _ [] Nothing _] = return d
67+toDecls [ValueDeclaration ident nameKind bs Nothing val] | all isVarBinder bs = do
68+ let args = map (\(VarBinder arg) -> arg) bs
69+ body = foldr (Abs . Left) val args
70+ return [ValueDeclaration ident nameKind [] Nothing body]
6871toDecls ds@(ValueDeclaration ident _ bs _ _ : _) = do
6972 let tuples = map toTuple ds
7073 unless (all ((== length bs) . length . fst) tuples) $
@@ -72,6 +75,10 @@ toDecls ds@(ValueDeclaration ident _ bs _ _ : _) = do
7275 return [makeCaseDeclaration ident tuples]
7376toDecls ds = return ds
7477
78+isVarBinder :: Binder -> Bool
79+isVarBinder (VarBinder _) = True
80+isVarBinder _ = False
81+
7582toTuple :: Declaration -> ([Binder], (Maybe Guard, Value))
7683toTuple (ValueDeclaration _ _ bs g val) = (bs, (g, val))
7784toTuple _ = error "Not a value declaration"
@@ -83,7 +90,7 @@ makeCaseDeclaration ident alternatives =
8390 args = take argPattern $ unusedNames (ident, alternatives)
8491 vars = map (Var . Qualified Nothing) args
8592 binders = [ CaseAlternative bs g val | (bs, (g, val)) <- alternatives ]
86− value = foldr (\arg ret -> Abs (Left arg) ret) (Case vars binders) args
93+ value = foldr (Abs . Left) (Case vars binders) args
8794 in
8895 ValueDeclaration ident Value [] Nothing value
8996
src/Language/PureScript/Sugar/Let.hs+1
@@ -28,5 +28,6 @@ import Language.PureScript.Declarations
2828desugarLetBindings :: [Module] -> [Module]
2929desugarLetBindings = everywhere (mkT go)
3030 where
31+ go (Let (VarBinder ident) value result) = App (Abs (Left ident) result) value
3132 go (Let binder value result) = Case [value] [CaseAlternative [binder] Nothing result]
3233 go other = other