A peer-to-peer stack for code collaboration
Some improvements to primFns (#360)
Merle Breitkreuz520177c72c00
diff --git a/src/Radicle/Internal/PrimFns.hs b/src/Radicle/Internal/PrimFns.hsindex c3fc7a0..7a78a1e 100644--- a/src/Radicle/Internal/PrimFns.hs+++ b/src/Radicle/Internal/PrimFns.hs@@ -177,9 +177,10 @@ purePrimFns = fromList $ allDocs $(Number n, vs) -> case Num.isInt n ofLeft _ -> throwErrorHere $ OtherError "drop: first argument must be an int"Right i -> case vs of- List xs -> pure . List $ drop i xs- Vec xs -> pure . Vec $ Seq.drop i xs- v -> throwErrorHere $ TypeError "drop" 1 TSequence v+ List xs -> pure . List $ drop i xs+ Vec xs -> pure . Vec $ Seq.drop i xs+ String xs -> pure . String $ T.drop i xs+ v -> throwErrorHere $ TypeError "drop" 1 TSequence v(v, _) -> throwErrorHere $ TypeError "drop" 0 TNumber v), ( "take"@@ -375,8 +376,8 @@ purePrimFns = fromList $ allDocs $, "Checks if a number is an integer.", oneArg "integral?" $ \caseNumber n -> case Num.isInteger n of- Left _ -> pure $ Boolean False- Right _ -> pure $ Boolean True+ Left _ -> pure ff+ Right _ -> pure ttv -> throwErrorHere $ TypeError "integral?" 0 TNumber v), ( "foldl-string"@@ -422,17 +423,20 @@ purePrimFns = fromList $ allDocs $, isTy "keyword", oneArg "keyword?" $ \caseKeyword _ -> pure tt- _ -> pure ff)+ _ -> pure ff+ ), ( "atom?", isTy "atom", oneArg "atom?" $ \case- Atom _ -> pure tt- _ -> pure ff)+ Atom _ -> pure tt+ _ -> pure ff+ ), ( "list?", isTy "list", oneArg "list?" $ \case- List _ -> pure tt- _ -> pure ff)+ List _ -> pure tt+ _ -> pure ff+ ), ( "vector?", isTy "vector", oneArg "vector?" $ \case@@ -442,8 +446,9 @@ purePrimFns = fromList $ allDocs $, ( "dict?", isTy "dict", oneArg "dict?" $ \case- Dict _ -> pure tt- _ -> pure ff)+ Dict _ -> pure tt+ _ -> pure ff+ ), ( "type", "Returns a keyword representing the type of the argument; one of:\\ `:atom`, `:keyword`, `:string`, `:number`, `:boolean`, `:list`,\@@ -454,17 +459,20 @@ purePrimFns = fromList $ allDocs $, isTy "string", oneArg "string?" $ \caseString _ -> pure tt- _ -> pure ff)+ _ -> pure ff+ ), ( "boolean?", isTy "boolean", oneArg "boolean?" $ \caseBoolean _ -> pure tt- _ -> pure ff)+ _ -> pure ff+ ), ( "number?", isTy "number", oneArg "number?" $ \caseNumber _ -> pure tt- _ -> pure ff)+ _ -> pure ff+ ), ( "member?", "Given `v` and structure `s`, checks if `x` exists in `s`. The structure `s`\\ may be a list, vector or dict. If it is a list or a vector, it checks if `v`\@@ -538,8 +546,8 @@ purePrimFns = fromList $ allDocs $, "Checks if a value represents a valid public key.", oneArg "public-key?" $\v -> case fromRad v of- Right (_ :: PublicKey) -> pure $ Boolean True- Left _ -> pure $ Boolean False+ Right (_ :: PublicKey) -> pure tt+ Left _ -> pure ff), ( "uuid?", "Checks if a string has the format of a UUID."