allow floating point values to be used with builtins.add. Fixes Issue #207.
This commit is contained in:
parent
3b304561f7
commit
43bb8d0558
|
@ -114,7 +114,7 @@ builtinsList = sequence [
|
|||
|
||||
, add0 Normal "nixPath" nixPath
|
||||
, add TopLevel "abort" throw_ -- for now
|
||||
, add' Normal "add" (arity2 ((+) @Integer))
|
||||
, add2 Normal "add" add_
|
||||
, add2 Normal "all" all_
|
||||
, add2 Normal "any" any_
|
||||
, add Normal "attrNames" attrNames
|
||||
|
@ -272,6 +272,16 @@ unsafeGetAttrPos x y = x >>= \x' -> y >>= \y' -> case (x', y') of
|
|||
length_ :: forall e m. MonadNix e m => m (NValue m) -> m (NValue m)
|
||||
length_ = toValue . (length :: [NThunk m] -> Int) <=< fromValue
|
||||
|
||||
add_ :: MonadNix e m => m (NValue m) -> m (NValue m) -> m (NValue m)
|
||||
add_ 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 $ Addition 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)) ->
|
||||
|
|
|
@ -124,6 +124,7 @@ renderValueFrame level = pure . (:[]) . \case
|
|||
ForcingThunk -> text "ForcingThunk"
|
||||
ConcerningValue _v -> text "ConcerningValue"
|
||||
Comparison _ _ -> text "Comparing"
|
||||
Addition _ _ -> text "Adding"
|
||||
Division _ _ -> text "Dividing"
|
||||
|
||||
Coercion x y ->
|
||||
|
|
|
@ -317,6 +317,7 @@ data ValueFrame m
|
|||
= ForcingThunk
|
||||
| ConcerningValue (NValue m)
|
||||
| Comparison (NValue m) (NValue m)
|
||||
| Addition (NValue m) (NValue m)
|
||||
| Division (NValue m) (NValue m)
|
||||
| Coercion ValueType ValueType
|
||||
| CoercionToJsonNF (NValueNF m)
|
||||
|
|
Loading…
Reference in a new issue