Skip to content

Commit

Permalink
inline and error message
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahCardoso committed Jun 18, 2024
1 parent 96103f8 commit 30a4e88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
16 changes: 4 additions & 12 deletions code/drasil-lang/lib/Language/Drasil/Expr/Lang.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,14 @@ instance Typed Expr Space where
-- If the inferred type of e is a valid Space, call allOfType with spaceValue
allOfType cxt exs spaceValue spaceValue
"Associative arithmetic operation expects all operands to be of the same expected type."
Left _ ->
Left l ->
-- Handle the case when sp is a Left value but spaceValue is invalid
Right "Invalid spaceValue encountered."
Right ("Expected all operands in addition/multiplication to be numeric, but found " ++ show l)
Right r ->
-- If sp is a Right value containing a TypeError
Right r

infer _ (AssocA op exs) =
case (op, exs) of
(Add, []) ->
-- Return a default value or an error for empty addition
Right "Associative addition requires at least one operand."
(Mul, []) ->
-- Return a default value or an error for empty multiplication
Right "Associative multiplication requires at least one operand."
-- Other cases...
infer _ (AssocA Add _) = Right "Associative addition requires at least one operand."
infer _ (AssocA Mul _) = Right "Associative multiplication requires at least one operand."

infer cxt (AssocB _ exs) = allOfType cxt exs S.Boolean S.Boolean
$ "Associative boolean operation expects all operands to be of the same type (" ++ show S.Boolean ++ ")."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ withParens prI a b = P.Row [parens (modelExpr a prI), P.Sup (modelExpr b prI)]

-- | Helper for properly rendering exponents.
pow :: PrintingInformation -> ModelExpr -> ModelExpr -> P.Expr
pow prI a@(AssocA Add _) b = withParens prI a b
pow prI a@(AssocA Mul _) b = withParens prI a b
pow prI a@(AssocA Add _) b = withParens prI a b
pow prI a@(AssocA Mul _) b = withParens prI a b
pow prI a@(ArithBinaryOp Subt _ _) b = withParens prI a b
pow prI a@(ArithBinaryOp Frac _ _) b = withParens prI a b
pow prI a@(ArithBinaryOp Pow _ _) b = withParens prI a b
Expand Down

0 comments on commit 30a4e88

Please sign in to comment.