From 60308358690d717a8aa33bbb821a9797e8f363e3 Mon Sep 17 00:00:00 2001 From: Lukas Pietzschmann Date: Wed, 17 Jul 2024 11:45:43 +0200 Subject: [PATCH] Fixed small bug in unit comparison The other change is just a cosmetic one --- src/Math/Haskellator/Internal/AstProcessingSteps/Evaluate.hs | 4 ++-- src/Math/Haskellator/Internal/TH/UnitGeneration.hs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Math/Haskellator/Internal/AstProcessingSteps/Evaluate.hs b/src/Math/Haskellator/Internal/AstProcessingSteps/Evaluate.hs index e8f1640..9820c71 100644 --- a/src/Math/Haskellator/Internal/AstProcessingSteps/Evaluate.hs +++ b/src/Math/Haskellator/Internal/AstProcessingSteps/Evaluate.hs @@ -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 diff --git a/src/Math/Haskellator/Internal/TH/UnitGeneration.hs b/src/Math/Haskellator/Internal/TH/UnitGeneration.hs index a7b404d..01591a8 100644 --- a/src/Math/Haskellator/Internal/TH/UnitGeneration.hs +++ b/src/Math/Haskellator/Internal/TH/UnitGeneration.hs @@ -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 |]