From 5f1e072868eecc1bc33949a4613034f3c9f98b8a Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Sat, 10 Aug 2019 15:38:18 -0400 Subject: [PATCH] Add Nat.fromText --- CONTRIBUTORS.markdown | 1 + parser-typechecker/src/Unison/Builtin.hs | 1 + parser-typechecker/src/Unison/Runtime/Rt1.hs | 2 ++ parser-typechecker/unison-parser-typechecker.cabal | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.markdown b/CONTRIBUTORS.markdown index 6590936dd..dbaf46456 100644 --- a/CONTRIBUTORS.markdown +++ b/CONTRIBUTORS.markdown @@ -22,3 +22,4 @@ The format for this list: name, GitHub handle, and then optional blurb about wha * Scott Christopher (@scott-christopher) * Alex Zolotko (@azolotko) * Ian Denhardt (@zenhack) +* Mitchell Rosen (@mitchellwrosen) diff --git a/parser-typechecker/src/Unison/Builtin.hs b/parser-typechecker/src/Unison/Builtin.hs index 5744dfb04..3d000af6d 100644 --- a/parser-typechecker/src/Unison/Builtin.hs +++ b/parser-typechecker/src/Unison/Builtin.hs @@ -241,6 +241,7 @@ builtinsSrc = , B "Nat.isOdd" $ nat --> boolean , B "Nat.toInt" $ nat --> int , B "Nat.toText" $ nat --> text + , B "Nat.fromText" $ text --> optional nat , B "Float.+" $ float --> float --> float , B "Float.-" $ float --> float --> float diff --git a/parser-typechecker/src/Unison/Runtime/Rt1.hs b/parser-typechecker/src/Unison/Runtime/Rt1.hs index 05a0a5470..c3246d0a5 100644 --- a/parser-typechecker/src/Unison/Runtime/Rt1.hs +++ b/parser-typechecker/src/Unison/Runtime/Rt1.hs @@ -331,6 +331,8 @@ builtinCompilationEnv = CompilationEnv (builtinsMap <> IR.builtins) mempty , mk1 "Float.truncate" atf (pure . I) truncate , mk1 "Nat.toText" atn (pure . T) (Text.pack . show) + , mk1 "Nat.fromText" att (pure . IR.maybeToOptional . fmap N) ( + (\x -> readMaybe x :: Maybe Word64) . Text.unpack) -- Float Utils , mk1 "Float.abs" atf (pure . F) abs diff --git a/parser-typechecker/unison-parser-typechecker.cabal b/parser-typechecker/unison-parser-typechecker.cabal index 3755e12f1..e27276aef 100644 --- a/parser-typechecker/unison-parser-typechecker.cabal +++ b/parser-typechecker/unison-parser-typechecker.cabal @@ -185,7 +185,7 @@ library io-streams, lens, ListLike, - megaparsec, + megaparsec >= 5.0.0 && < 7.0.0, memory, mmorph, monad-loops,