@@ -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