add builtins.mul, issue #250

This commit is contained in:
Tim Sears 2018-04-29 11:43:06 -07:00
parent ad18b950ac
commit a49a424813
4 changed files with 14 additions and 1 deletions

@ -1 +1 @@
Subproject commit 8cc0796bec18057b3feadd1c39ed3f669078a075
Subproject commit 66707728d0b82754354f0bcd24f32e43500bd86e

View file

@ -164,6 +164,7 @@ builtinsList = sequence [
, add Normal "listToAttrs" listToAttrs
, add2 TopLevel "map" map_
, add2 Normal "match" match_
, add2 Normal "mul" mul_
, add Normal "parseDrvName" parseDrvName
, add2 Normal "partition" partition_
, add Normal "pathExists" pathExists_
@ -282,6 +283,16 @@ add_ x y = x >>= \x' -> y >>= \y' -> case (x', y') of
(_, _) ->
throwError $ Addition x' y'
mul_ :: MonadNix e m => m (NValue m) -> m (NValue m) -> m (NValue m)
mul_ x y = x >>= \x' -> y >>= \y' -> case (x', y') of
(NVConstant (NInt x), NVConstant (NInt y)) ->
toNix ( x * y :: Integer)
(NVConstant (NFloat x), NVConstant (NInt y)) -> toNix (x * fromInteger y)
(NVConstant (NInt x), NVConstant (NFloat y)) -> toNix (fromInteger x * y)
(NVConstant (NFloat x), NVConstant (NFloat y)) -> toNix (x * y)
(_, _) ->
throwError $ Multiplication x' y'
div_ :: MonadNix e m => m (NValue m) -> m (NValue m) -> m (NValue m)
div_ x y = x >>= \x' -> y >>= \y' -> case (x', y') of
(NVConstant (NInt x), NVConstant (NInt y)) ->

View file

@ -126,6 +126,7 @@ renderValueFrame level = pure . (:[]) . \case
Comparison _ _ -> text "Comparing"
Addition _ _ -> text "Adding"
Division _ _ -> text "Dividing"
Multiplication _ _ -> text "Multiplying"
Coercion x y ->
text desc <> text (describeValue x)

View file

@ -318,6 +318,7 @@ data ValueFrame m
| ConcerningValue (NValue m)
| Comparison (NValue m) (NValue m)
| Addition (NValue m) (NValue m)
| Multiplication (NValue m) (NValue m)
| Division (NValue m) (NValue m)
| Coercion ValueType ValueType
| CoercionToJsonNF (NValueNF m)