Skip to content

Commit

Permalink
remove function clause from language
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Sep 26, 2023
1 parent 5368b2f commit f186c7f
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 69 deletions.
10 changes: 0 additions & 10 deletions src/Juvix/Compiler/Internal/Extra/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ subsHoles s = over leafExpressions helper
ExpressionInstanceHole h -> fromMaybe e (s ^. at h)
_ -> e

instance HasExpressions FunctionClause where
leafExpressions f c = do
_clauseBody <- leafExpressions f (c ^. clauseBody)
_clausePatterns <- traverse (leafExpressions f) (c ^. clausePatterns)
pure FunctionClause {_clauseName = c ^. clauseName, ..}

instance HasExpressions Example where
leafExpressions f = traverseOf exampleExpression (leafExpressions f)

Expand Down Expand Up @@ -532,10 +526,6 @@ clauseLhsAsExpression :: Name -> [PatternArg] -> Expression
clauseLhsAsExpression clName pats =
foldApplication (toExpression clName) (map toApplicationArg pats)

clauseLhsAsExpressionREMOVE :: FunctionClause -> Expression
clauseLhsAsExpressionREMOVE cl =
foldApplication (toExpression (cl ^. clauseName)) (map toApplicationArg (cl ^. clausePatterns))

infix 4 ==%

(==%) :: (IsExpression a, IsExpression b) => a -> b -> HashSet Name -> Bool
Expand Down
5 changes: 0 additions & 5 deletions src/Juvix/Compiler/Internal/Extra/DependencyBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ goConstructorDef indName c = do
addEdge (c ^. inductiveConstructorName) indName
goExpression (Just indName) (c ^. inductiveConstructorType)

goFunctionClause :: (Members '[State DependencyGraph, State StartNodes, Reader ExportsTable] r) => Name -> FunctionClause -> Sem r ()
goFunctionClause p c = do
mapM_ (goPattern (Just p)) (c ^. clausePatterns)
goExpression (Just p) (c ^. clauseBody)

goPattern :: forall r. (Member (State DependencyGraph) r) => Maybe Name -> PatternArg -> Sem r ()
goPattern n p = case p ^. patternArgPattern of
PatternVariable {} -> return ()
Expand Down
13 changes: 0 additions & 13 deletions src/Juvix/Compiler/Internal/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ data FunctionDef = FunctionDef

instance Hashable FunctionDef

data FunctionClause = FunctionClause
{ _clauseName :: FunctionName,
_clausePatterns :: [PatternArg],
_clauseBody :: Expression
}
deriving stock (Eq, Generic, Data)

instance Hashable FunctionClause

data Iden
= IdenFunction Name
| IdenConstructor Name
Expand Down Expand Up @@ -328,7 +319,6 @@ makeLenses ''Example
makeLenses ''PatternArg
makeLenses ''Import
makeLenses ''FunctionDef
makeLenses ''FunctionClause
makeLenses ''InductiveDef
makeLenses ''AxiomDef
makeLenses ''ModuleBody'
Expand Down Expand Up @@ -439,9 +429,6 @@ instance HasLoc LambdaClause where
instance HasLoc Lambda where
getLoc l = getLocSpan (l ^. lambdaClauses)

instance HasLoc FunctionClause where
getLoc f = getLoc (f ^. clauseName) <> getLoc (f ^. clauseBody)

instance HasLoc FunctionDef where
getLoc f = getLoc (f ^. funDefName) <> getLoc (f ^. funDefBody)

Expand Down
7 changes: 0 additions & 7 deletions src/Juvix/Compiler/Internal/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,6 @@ instance PrettyCode PreLetStatement where
ppCode = \case
PreLetFunctionDef f -> ppCode f

instance PrettyCode FunctionClause where
ppCode c = do
funName <- ppCode (c ^. clauseName)
clausePatterns' <- hsepMaybe <$> mapM ppCodeAtom (c ^. clausePatterns)
clauseBody' <- ppCode (c ^. clauseBody)
return $ nest 2 (funName <+?> clausePatterns' <+> kwAssign <+> clauseBody')

instance PrettyCode Import where
ppCode i = do
name' <- ppCode (i ^. importModule . moduleIxModule . moduleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,6 @@ checkFunctionBody ari body = do
}
}

checkFunctionClause ::
(Members '[Reader InfoTable, NameIdGen, Error ArityCheckerError] r) =>
Arity ->
FunctionClause ->
Sem r FunctionClause
checkFunctionClause ari cl = do
hint <- guessArity (cl ^. clauseBody)
(patterns', locals, bodyAri) <- checkLhs loc hint ari (cl ^. clausePatterns)
body' <- runReader locals (checkExpression bodyAri (cl ^. clauseBody))
return
FunctionClause
{ _clauseName = cl ^. clauseName,
_clausePatterns = patterns',
_clauseBody = body'
}
where
name = cl ^. clauseName
loc = getLoc name

simplelambda :: a
simplelambda = error "simple lambda expressions are not supported by the arity checker"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,6 @@ lookupVar v = HashMap.lookupDefault err v <$> asks (^. localTypes)
where
err = error $ "internal error: could not find var " <> ppTrace v

checkFunctionClause ::
forall r.
(Members '[HighlightBuilder, Reader InfoTable, State FunctionsTable, Error TypeCheckerError, NameIdGen, Inference, Builtins, State TypesTable, Output Example, Reader LocalVars, Termination] r) =>
Expression ->
FunctionClause ->
Sem r FunctionClause
checkFunctionClause clauseType FunctionClause {..} = do
(patterns', body') <- checkClause clauseType _clausePatterns _clauseBody
return
FunctionClause
{ _clauseBody = body',
_clausePatterns = patterns',
..
}

-- | helper function for function clauses and lambda functions
checkClause ::
forall r.
Expand Down

0 comments on commit f186c7f

Please sign in to comment.