Skip to content

Commit

Permalink
Fixed small bug in unit comparison
Browse files Browse the repository at this point in the history
The other change is just a cosmetic one
  • Loading branch information
LukasPietzschmann committed Jul 17, 2024
1 parent 66d1700 commit 6030835
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Math/Haskellator/Internal/AstProcessingSteps/Evaluate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ execVal = return

execBinOp :: Value Dimension -> Op -> Value Dimension -> SimpleAstFold (Value Dimension)
execBinOp lhs Plus rhs | unit lhs =~= unit rhs = return $ combineValues (+) lhs rhs
| otherwise = throwError $ Error RuntimeError $ "Cannot add units " ++ show lhs ++ " and " ++ show rhs
| otherwise = throwError $ Error RuntimeError $ "Cannot add units " ++ show (unit lhs) ++ " and " ++ show (unit rhs)
execBinOp lhs Minus rhs | unit lhs =~= unit rhs = return $ combineValues (-) lhs rhs
| otherwise = throwError $ Error RuntimeError $ "Cannot subtract units " ++ show lhs ++ " and " ++ show rhs
| otherwise = throwError $ Error RuntimeError $ "Cannot subtract units " ++ show (unit lhs) ++ " and " ++ show (unit rhs)
execBinOp lhs Mult rhs = do
let u = mergeUnits (unit lhs) (unit rhs)
return $ Value (value lhs * value rhs) u
Expand Down
1 change: 1 addition & 0 deletions src/Math/Haskellator/Internal/TH/UnitGeneration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ genUnitExp = [d|
show (UnitExp u i) = show u ++ "^" ++ show i

instance Eq UnitExp where
(UnitExp $(return $ ConP (mkName "Multiplier") [] []) _) == (UnitExp $(return $ ConP (mkName "Multiplier") [] []) _) = True
(UnitExp u1 i1) == (UnitExp u2 i2) = u1 == u2 && i1 == i2
|]

Expand Down

0 comments on commit 6030835

Please sign in to comment.