Skip to content

Commit

Permalink
default case
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Nov 20, 2024
1 parent d280fe7 commit 057fdbb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Juvix/Compiler/Internal/Translation/FromConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -569,19 +569,35 @@ deriveEq instanceName funParams (eqName, args) = do
let loc = getLoc eqName
band <- getBuiltin loc BuiltinBoolAnd
btrue <- getBuiltin loc BuiltinBoolTrue
bfalse <- getBuiltin loc BuiltinBoolFalse
bisEqual <- getBuiltin loc BuiltinIsEqual
case nonEmpty (d ^. Internal.inductiveInfoConstructors) of
Nothing -> return (Internal.toExpression btrue)
Just cs -> do
cl' <- mapM (lambdaClause band btrue bisEqual) cs
defaultCl' <-
if
| notNull (NonEmpty.tail cs) -> Just <$> defaultLambdaClause bfalse
| otherwise -> return Nothing
return
( Internal.ExpressionLambda
Internal.Lambda
{ _lambdaType = Nothing,
_lambdaClauses = cl'
_lambdaClauses = snocNonEmptyMaybe cl' defaultCl'
}
)
where
defaultLambdaClause :: Internal.Name -> Sem r Internal.LambdaClause
defaultLambdaClause btrue = do
let loc = getLoc eqName
p1 <- Internal.genWildcard loc Internal.Explicit
p2 <- Internal.genWildcard loc Internal.Explicit
return
Internal.LambdaClause
{ _lambdaPatterns = p1 :| [p2],
_lambdaBody = Internal.toExpression btrue
}

lambdaClause ::
Internal.FunctionName ->
Internal.FunctionName ->
Expand Down Expand Up @@ -620,7 +636,7 @@ deriveEq instanceName funParams (eqName, args) = do
def <- getDefinedConstructor c
let cargs :: [Internal.FunctionParameter] = Internal.constructorArgs (def ^. Internal.constructorInfoType)
unless (all ((== Explicit) . (^. Internal.paramImplicit)) cargs) (error "TODO all args must be explicit")
return (length args)
return (length cargs)

goFunctionDef ::
forall r.
Expand Down

0 comments on commit 057fdbb

Please sign in to comment.