From aba666c5bc7a46cdc7de7e2a36869456c34909bd Mon Sep 17 00:00:00 2001 From: aarne Date: Tue, 5 Nov 2013 17:28:47 +0000 Subject: linearization by chunks in the GF shell: a new command 'lc' needed because 'l' requires type checking and trees with metavariable function heads don't type check. This will hopefully be a temporary command. --- src/runtime/haskell/PGF/Expr.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/runtime/haskell') diff --git a/src/runtime/haskell/PGF/Expr.hs b/src/runtime/haskell/PGF/Expr.hs index 01b791847..264be4aaa 100644 --- a/src/runtime/haskell/PGF/Expr.hs +++ b/src/runtime/haskell/PGF/Expr.hs @@ -2,7 +2,7 @@ module PGF.Expr(Tree, BindType(..), Expr(..), Literal(..), Patt(..), Equation(.. readExpr, showExpr, pExpr, pBinds, ppExpr, ppPatt, pattScope, mkAbs, unAbs, - mkApp, unApp, + mkApp, unApp, unAppForm, mkStr, unStr, mkInt, unInt, mkDouble, unDouble, @@ -112,13 +112,19 @@ mkApp f es = foldl EApp (EFun f) es -- | Decomposes an expression into application of function unApp :: Expr -> Maybe (CId,[Expr]) -unApp = extract [] +unApp e = case unAppForm e of + (EFun f,es) -> Just (f,es) + _ -> Nothing + +-- | Decomposes an expression into an application of a constructor such as a constant or a metavariable +unAppForm :: Expr -> (Expr,[Expr]) +unAppForm = extract [] where - extract es (EFun f) = Just (f,es) + extract es f@(EFun _) = (f,es) extract es (EApp e1 e2) = extract (e2:es) e1 extract es (ETyped e ty)= extract es e extract es (EImplArg e) = extract es e - extract es _ = Nothing + extract es h = (h,es) -- | Constructs an expression from string literal mkStr :: String -> Expr -- cgit v1.2.3