Skip to content

Commit

Permalink
PureScript: fix MalTime mathematical operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsekut authored and kanaka committed Dec 17, 2021
1 parent 6ebb4d8 commit 4a3f6a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions impls/purs/src/Core.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Core (ns) where
import Prelude

import Data.DateTime.Instant (unInstant)
import Data.Int (ceil)
import Data.Int (ceil, toNumber)
import Data.List (List(..), concat, drop, foldM, fromFoldable, length, reverse, (:))
import Data.Map.Internal as Map
import Data.Maybe (Maybe(..))
Expand Down Expand Up @@ -135,10 +135,12 @@ falseQ _ = false

-- Numeric functions

numOp (Int Int Int) MalFn
numOp op ((MalInt n1) : (MalInt n2) : Nil) = pure $ MalInt $ op n1 n2
numOp op (MalTime n1 : MalTime n2 : Nil) = pure $ MalInt $ op (ceil n1) (ceil n2)
numOp _ _ = throw "invalid operator"
numOp (Number Number Number) MalFn
numOp op (MalInt n1 : MalInt n2 : Nil) = pure $ MalInt $ ceil $ op (toNumber n1) (toNumber n2)
numOp op (MalInt n1 : MalTime n2 : Nil) = pure $ MalInt $ ceil $ op (toNumber n1) n2
numOp op (MalTime n1 : MalInt n2 : Nil) = pure $ MalInt $ ceil $ op n1 (toNumber n2)
numOp op (MalTime n1 : MalTime n2 : Nil) = pure $ MalTime $ op n1 n2
numOp _ _ = throw "invalid operator"


cmpOp (Int Int Boolean) List MalExpr Effect MalExpr
Expand All @@ -148,8 +150,9 @@ cmpOp _ _ = throw "invalid operator"


numberQ :: MalExpr -> Boolean
numberQ (MalInt _) = true
numberQ _ = false
numberQ (MalInt _) = true
numberQ (MalTime _) = true
numberQ _ = false



Expand Down
1 change: 1 addition & 0 deletions impls/purs/src/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ instance Eq MalExpr where
eq MalNil MalNil = true
eq (MalBoolean a) (MalBoolean b) = a == b
eq (MalInt a) (MalInt b) = a == b
eq (MalTime a) (MalTime b) = a == b
eq (MalString a) (MalString b) = a == b
eq (MalKeyword a) (MalKeyword b) = a == b
eq (MalSymbol a) (MalSymbol b) = a == b
Expand Down

0 comments on commit 4a3f6a1

Please sign in to comment.