A peer-to-peer stack for code collaboration
Revert "Merge pull request #200 from oscoin/dynamic-completion"
Julian K. Arni6c013120d49a
diff --git a/.hlint.yaml b/.hlint.yamlindex 95449e8..09ab05c 100644--- a/.hlint.yaml+++ b/.hlint.yaml@@ -27,7 +27,6 @@- ignore: {name: Redundant do}- ignore: {name: Use ++}- ignore: {name: Use &&}-- ignore: {name: Use <$>}- ignore: {name: Use fromMaybe}- ignore: {name: Eta reduce}- ignore: {name: Use lambda-case}diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yamlindex ede97e9..a4cc491 100644--- a/.stylish-haskell.yaml+++ b/.stylish-haskell.yaml@@ -200,6 +200,5 @@ language_extensions:- ScopedTypeVariables- StandaloneDeriving- TupleSections- - TypeApplications- TypeFamilies- TypeOperatorsdiff --git a/docs/source/reference.rst b/docs/source/reference.rstindex 4a46fb9..5b26faa 100644--- a/docs/source/reference.rst+++ b/docs/source/reference.rst@@ -175,12 +175,6 @@ Multiplies two numbers together.Substracts one number from another.-``/``-~~~~~--Divides one number by another. Throws an exception if the second-argument is 0.-``<``~~~~~@@ -265,12 +259,6 @@ Given a value ``x``, and two functions ``f`` and ``g``, checks if ``x``is a list with a head. If so applies ``f`` to the head, otherwise calls``g`` with no args.-``for-each``-~~~~~~~~~~~~--(for-each ls cb) calls ``cb`` for each element in the list ``ls``, for-its side effect. always returns ``nil``.-Vectors-------@@ -292,12 +280,6 @@ Adds an element to the left side of a vector.Adds an element to the right side of a vector.-``for-each-vec``-~~~~~~~~~~~~~~~~--(for-each-vec v cb) calls ``cb`` for each element in ``v``, for its side-effect. always returns ``nil``.-Sequences---------@@ -369,8 +351,7 @@ Functions for manipulating dicts.~~~~~~~~Given an even number of arguments, creates a dict where the ``2i``-th-argument is the key for the ``2i+1``\ th argument. If one of the even-indexed arguments is not hashable then an exception is thrown.+argument is the key for the ``2i+1``\ th argument.``lookup``~~~~~~~~~~@@ -385,7 +366,7 @@ thrown.Given ``k``, ``v`` and a dict ``d``, returns a dict with the sameassociations as ``d`` but with ``k`` associated to ``d``. If ``d`` isn't-a dict or if ``k`` isn't hashable then an exception is thrown.+a dict then an exception is thrown.``delete``~~~~~~~~~~@@ -608,11 +589,6 @@ Input/OutputEffectful functions. These functions are not available in 'pure' chains,but are available in the local REPL.-``put-str!``-~~~~~~~~~~~~--Outputs a string verbatim.-``print!``~~~~~~~~~~@@ -623,12 +599,6 @@ Pretty-prints a value.Reads a single line of input and returns it as a string.-``get-expression!``-~~~~~~~~~~~~~~~~~~~--Reads a line of input and returns it as a string. Takes a list of-completion words.-``load!``~~~~~~~~~@@ -867,11 +837,6 @@ functions before sending these to a remote chain.Return an empty chain dictionary with the given url.-``@var``-~~~~~~~~--A lens for variables in states of chains.-``eval-in-chain``~~~~~~~~~~~~~~~~~diff --git a/exe/Doc.hs b/exe/Doc.hsindex df2c848..50d336c 100644--- a/exe/Doc.hs+++ b/exe/Doc.hs@@ -7,7 +7,7 @@ import Protoludeimport qualified Data.Text as Timport Options.Applicativeimport Radicle-import qualified Radicle.Internal.Input as Input+import System.Console.Haskeline (defaultSettings, runInputT)import Text.Pandocmain :: IO ()@@ -25,7 +25,7 @@ run :: FilePath -> IO ()run f = dotxt <- readFile fpand <- runIOorExplode $ readMarkdown def txt- res <- Input.runInputT Nothing $ runLang replBindings $ interpretMany (toS f) $ getCode pand+ res <- runInputT defaultSettings $ runLang replBindings $ interpretMany (toS f) $ getCode pandcase res of(Left err, _) -> die . toS $ "Error: " ++ show err_ -> pure ()diff --git a/exe/RadicleExe.hs b/exe/RadicleExe.hsindex f5baed5..fd0d3fc 100644--- a/exe/RadicleExe.hs+++ b/exe/RadicleExe.hs@@ -11,9 +11,9 @@ import Prelude (String)import Protolude hiding (TypeError, option, sourceFile)import Radicleimport Servant.Client+import System.Console.Haskeline (InputT)import System.Directory (doesFileExist)-import qualified Radicle.Internal.Input as Inputimport qualified Radicle.Internal.Number as Numimport qualified Radicle.Internal.PrimFns as PrimFns@@ -72,10 +72,10 @@ opts = Opts-- * Primops-bindings :: HttpClient.Manager -> Bindings (PrimFns (Input.InputT IO))+bindings :: HttpClient.Manager -> Bindings (PrimFns (InputT IO))bindings mgr = addPrimFns (replPrimFns <> clientPrimFns mgr) pureEnv-clientPrimFns :: HttpClient.Manager -> PrimFns (Input.InputT IO)+clientPrimFns :: HttpClient.Manager -> PrimFns (InputT IO)clientPrimFns mgr = fromList . PrimFns.allDocs $ [sendPrimop, receivePrimop]wheresendPrimop =diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hsindex 370dbd6..46fd96e 100644--- a/exe/ReferenceDoc.hs+++ b/exe/ReferenceDoc.hs@@ -11,12 +11,12 @@ import qualified Data.Map.Strict as Mapimport qualified Data.Text as Timport qualified GHC.Exts as GhcExtsimport Radicle-import qualified Radicle.Internal.Input as Input+import System.Console.Haskeline (defaultSettings, runInputT)import Text.Pandocmain :: IO ()main = do- res_ <- Input.runInputT Nothing $+ res_ <- runInputT defaultSettings $interpret"reference-doc""(do (load! \"rad/prelude.rad\") (get-current-env))"@@ -83,8 +83,8 @@ main = doseqs = ["nth", "foldl", "foldr", "map", "seq", "take", "drop", "sort-by"]lists =[ "list", "nil", "head", "tail", "empty?", "cons", "reverse", "length", "concat"- , "filter", "range", "list-with-head", "for-each" ]- vecs = ["<>", "add-left", "add-right", "for-each-vec" ]+ , "filter", "range", "list-with-head" ]+ vecs = ["<>", "add-left", "add-right"]dicts =["dict", "lookup", "insert", "delete", "dict-from-list", "keys", "values", "rekey", "map-values", "modify-map", "delete-many"]diff --git a/package.yaml b/package.yamlindex 0c28568..522efd6 100644--- a/package.yaml+++ b/package.yaml@@ -205,6 +205,5 @@ default-extensions:- ScopedTypeVariables- StandaloneDeriving- TupleSections-- TypeApplications- TypeFamilies- TypeOperatorsdiff --git a/rad/prelude.rad b/rad/prelude.radindex 428f43f..ab952f8 100644--- a/rad/prelude.rad+++ b/rad/prelude.rad@@ -1,5 +1,5 @@-(load! "rad/prelude/io.rad")(load! "rad/prelude/test.rad")+(load! "rad/prelude/io.rad")(load! "rad/prelude/bool.rad")(load! "rad/prelude/exception.rad")(load! "rad/prelude/recursion.rad")diff --git a/rad/prelude/dict.rad b/rad/prelude/dict.radindex b07f845..f9b47aa 100644--- a/rad/prelude/dict.rad+++ b/rad/prelude/dict.rad@@ -19,14 +19,12 @@(def keys"Given a `dict`, returns a vector of its keys."(fn [d]- (map (fn [s] (nth 0 s)) (seq d))))+ (map head (seq d))))(:test "keys"[ (keys {:one 1 :two 2}) ==> [:one :two] ])-;; values-(def values"Given a `dict`, returns a vector of its values."(fn [d]diff --git a/rad/prelude/exception.rad b/rad/prelude/exception.radindex 458309c..d60b6ad 100644--- a/rad/prelude/exception.rad+++ b/rad/prelude/exception.rad@@ -1,5 +1,5 @@(:test "catch handles scope correctly";; Issue #191, catch used to accidentally use the lexical environment of;; the `throw` that generated the exception.- [ ((fn [body handler] (catch 'any (body) handler)) (fn [] (throw 'foo "foo")) (fn [e stack] #t)) ==> #t ]+ [ ((fn [body handler] (catch 'any (body) handler)) (fn [] (throw 'foo "foo")) (fn [e] #t)) ==> #t ])diff --git a/rad/prelude/io.rad b/rad/prelude/io.radindex d4218ac..221b857 100644--- a/rad/prelude/io.rad+++ b/rad/prelude/io.rad@@ -18,7 +18,3 @@(document 'send-code!'(("chain-id" string) ("filename" string))"Send code from a file to a remote chain.")--(def print!- "Pretty-prints a value."- (fn [x] (put-str! (show x))))diff --git a/rad/prelude/list.rad b/rad/prelude/list.radindex 857de5e..d374f0e 100644--- a/rad/prelude/list.rad+++ b/rad/prelude/list.rad@@ -107,22 +107,3 @@(f (head x))(g))(g))))---;; imperative for each--(def-rec for-each- "(for-each ls cb) calls `cb` for each element in the list `ls`, for its side- effect. always returns `nil`."- (fn [ls cb]- (if (empty? ls)- nil- (do (cb (head ls))- (for-each (tail ls) cb)))))--(def for-each-vec- "(for-each-vec v cb) calls `cb` for each element in `v`, for its side effect.- always returns `nil`."- (fn [v cb]- (for-each (range 0 (- (length v) 1)) (fn [i]- (cb (nth i v))))))diff --git a/rad/prelude/test.rad b/rad/prelude/test.radindex 07d9ce4..f9b30ce 100644--- a/rad/prelude/test.rad+++ b/rad/prelude/test.rad@@ -2,7 +2,7 @@(def is-test-env"True iff file is being run as part of the Haskell suite"- (catch 'any (eq? test-env__ #t) (fn [x stack] #f)))+ (catch 'any (eq? test-env__ #t) (fn [x] #f)));; Annoyingly verbose since we have neither the prelude nor pattern-matching.(def evaldiff --git a/rad/repl.rad b/rad/repl.radindex 6c77f95..eda4638 100644--- a/rad/repl.rad+++ b/rad/repl.rad@@ -2,24 +2,15 @@;; The Repl-(def render-exception! (fn [e stack]- (def show-e (if (eq? (type e) :string) e (show e)))- (put-str! (string-append "Exception: " show-e))- (for-each-vec stack put-str!)))+(def read-line-or-exit! (fn []+ (def line (get-line!))+ (if (eq? line nil)+ (exit!)+ (read line))))-(def repl (fn []- (def-rec repl-rec (fn [st]- (def line (get-expression! (keys (lookup :env st))))- (def cur-eval (lookup :val (lookup 'eval (lookup :env st))))- (if (eq? line nil)- nil- (do- (def new-st (catch 'any (do (def ret (cur-eval (read line) st))- (print! (head ret))- (head (tail ret)))- (fn [e stack] (render-exception! e stack)- st)))- (repl-rec new-st)))))- (repl-rec (get-current-env))))+(def repl+ {:name "repl"+ ;; Parse errors are thrown here+ :getter read-line-or-exit!})-(repl)+(subscribe-to! repl print!)diff --git a/scripts/ci-tests.sh b/scripts/ci-tests.shindex 6929023..4eb9216 100755--- a/scripts/ci-tests.sh+++ b/scripts/ci-tests.sh@@ -6,7 +6,7 @@set -e -xBASEDIR=$(dirname $BASH_SOURCE)/..cd $BASEDIR-./scripts/hottags.sh+hothasktags -XLambdaCase -XTypeFamilies -XScopedTypeVariables -XFunctionalDependencies -XTupleSections -XExplicitNamespaces -XStandaloneDeriving -XDefaultSignatures -R src > TAGSstack exec hlint ../scripts/check-fmt.shstack test --fastdiff --git a/scripts/hottags.sh b/scripts/hottags.shindex 62e40fe..6bd4b53 100755--- a/scripts/hottags.sh+++ b/scripts/hottags.sh@@ -6,4 +6,4 @@BASEDIR=$(dirname $BASH_SOURCE)/..cd $BASEDIR-hothasktags -XLambdaCase -XTypeFamilies -XScopedTypeVariables -XFunctionalDependencies -XTupleSections -XExplicitNamespaces -XStandaloneDeriving -XDefaultSignatures -XTypeApplications -R src > TAGS+hothasktags -XLambdaCase -XTypeFamilies -XScopedTypeVariables -XFunctionalDependencies -XTupleSections -XExplicitNamespaces -XStandaloneDeriving -XDefaultSignatures -R src > TAGSdiff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex befdf1e..1261749 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -26,7 +26,6 @@ import qualified Data.Sequence as Seqimport Generics.Eotimport qualified GHC.Exts as GhcExtsimport qualified Text.Megaparsec.Error as Par-import Text.Megaparsec.Pos (sourcePosPretty)import Radicle.Internal.Annotation (Annotated)import qualified Radicle.Internal.Annotation as Ann@@ -478,10 +477,11 @@ specialForms = Map.fromList $ first Ident <$>mlabel <- baseEval lhandlerclo <- baseEval handlercase mlabel of- Atom label -> baseEval form `catchError` \(LangError stack e) -> do+ -- TODO reify stack+ Atom label -> baseEval form `catchError` \(LangError _stack e) -> do(thrownLabel, thrownValue) <- errorDataToValue eif thrownLabel == label || label == Ident "any"- then handlerclo $$ [thrownValue, toRad stack]+ then handlerclo $$ [thrownValue]else baseEval form_ -> throwErrorHere $ TypeError "catch: first argument must be atom"xs -> throwErrorHere $ WrongNumberOfArgs "catch" 3 (length xs))@@ -541,9 +541,6 @@ instance FromRad t (Annotated t ValueF) whereinstance CPA t => FromRad t Rational wherefromRad (Number n) = pure nfromRad _ = Left "Not a number"-instance (CPA t) => FromRad t Ident where- fromRad (Atom i) = pure i- fromRad _ = Left "Expecting identifier"instance CPA t => FromRad t Scientific wherefromRad = fromRad >=> Num.isSciinstance CPA t => FromRad t Int where@@ -628,13 +625,10 @@ instance ToRad Ann.WithPos (Bindings m) where[ (Keyword $ Ident "env", toRad $ bindingsEnv x), (Keyword $ Ident "refs", List $ IntMap.elems (bindingsRefs x))]-instance (CPA t) => ToRad t Ann.SrcPos where- toRad (Ann.SrcPos p) = toRad (toS (sourcePosPretty p) :: Text)- toRad (Ann.InternalPos p) = toRad p--- * Helpers+-- Loc is the source location of the application.callFn :: Monad m => Value -> [Value] -> Lang m ValuecallFn f vs = case f ofLambda bnds body closure ->diff --git a/src/Radicle/Internal/Effects.hs b/src/Radicle/Internal/Effects.hsindex 57933c6..747e116 100644--- a/src/Radicle/Internal/Effects.hs+++ b/src/Radicle/Internal/Effects.hs@@ -10,11 +10,20 @@ import Data.Text.Prettyprint.Doc (pretty)import Data.Text.Prettyprint.Doc.Render.Terminal (putDoc)import qualified Data.Time as Timeimport GHC.Exts (IsList(..))+import System.Console.Haskeline+ ( CompletionFunc+ , InputT+ , completeWord+ , defaultSettings+ , historyFile+ , runInputT+ , setComplete+ , simpleCompletion+ )import Radicle.Internal.Coreimport Radicle.Internal.Cryptoimport Radicle.Internal.Effects.Capabilities-import qualified Radicle.Internal.Input as Inputimport Radicle.Internal.Interpretimport Radicle.Internal.Prettyimport Radicle.Internal.PrimFns@@ -28,19 +37,21 @@ type ReplM m =, GetEnv (Lang m) Value, SetEnv (Lang m) Value )-instance MonadRandom (Input.InputT IO) where+instance MonadRandom (InputT IO) wheregetRandomBytes = liftIO . getRandomBytesinstance MonadRandom m => MonadRandom (LangT (Bindings (PrimFns m)) m) wheregetRandomBytes = lift . getRandomBytes-instance UUID.MonadUUID (Input.InputT IO) where+instance UUID.MonadUUID (InputT IO) whereuuid = liftIO UUID.uuidinstance UUID.MonadUUID m => UUID.MonadUUID (LangT (Bindings (PrimFns m)) m) whereuuid = lift UUID.uuid-repl :: Maybe FilePath -> Text -> Text -> Bindings (PrimFns (Input.InputT IO)) -> IO ()+repl :: Maybe FilePath -> Text -> Text -> Bindings (PrimFns (InputT IO)) -> IO ()repl histFile preFileName preCode bindings = do- r <- Input.runInputT histFile+ let settings = setComplete completion+ $ defaultSettings { historyFile = histFile }+ r <- runInputT settings$ fmap fst $ runLang bindings$ void $ interpretMany preFileName preCodecase r of@@ -48,17 +59,31 @@ repl histFile preFileName preCode bindings = doLeft e -> putDoc $ pretty eRight () -> pure ()+completion :: Monad m => CompletionFunc m+completion = completeWord Nothing ['(', ')', ' ', '\n'] go+ where+ -- Any type for first param will do+ bnds :: Bindings (PrimFns (InputT IO))+ bnds = replBindings++ go s = pure $ fmap simpleCompletion+ $ filter (s `isPrefixOf`)+ $ fmap (T.unpack . fromIdent)+ $ (Map.keys . fromEnv $ bindingsEnv bnds)+ <> Map.keys (getPrimFns $ bindingsPrimFns bnds)+replBindings :: ReplM m => Bindings (PrimFns m)replBindings = addPrimFns replPrimFns pureEnvreplPrimFns :: ReplM m => PrimFns mreplPrimFns = fromList $ allDocs $- [ ( "put-str!"- , "Outputs a string verbatim."- , oneArg "put-str!" $ \case- String str -> putStrS str >> pure nil- _ -> throwErrorHere $ TypeError "put-str!: expects a string"- )+ [ ("print!"+ , "Pretty-prints a value."+ , \case+ [x] -> do+ putStrS (renderPrettyDef x)+ pure nil+ xs -> throwErrorHere $ WrongNumberOfArgs "print!" 1 (length xs)), ( "doc!", "Prints the documentation attached to a value and returns `()`. To retrieve\@@ -99,16 +124,6 @@ replPrimFns = fromList $ allDocs $xs -> throwErrorHere $ WrongNumberOfArgs "get-line!" 0 (length xs))- , ( "get-expression!"- , "Reads a line of input and returns it as a string. Takes a list of completion \- \words."- , \case- [complV] -> do- compl <- hoistEither . first (toLangError . OtherError) $ fromRad complV- maybe nil toRad <$> getLineCompletionS (map fromIdent compl)- xs -> throwErrorHere $ WrongNumberOfArgs "get-expression!" 1 (length xs)- )-, ("subscribe-to!", "Expects a dict `s` (representing a subscription) and a function `f`. The dict\\ `s` should have a function `getter` at the key `:getter`. This function is called\@@ -146,10 +161,9 @@ replPrimFns = fromList $ allDocs $void $ withEnv (const e) (fn $$ [quote line])_ -> throwErrorHere $ TypeError "subscribe-to!: Expected dict"xs -> throwErrorHere $ WrongNumberOfArgs "subscribe-to!" 2 (length xs))-, ( "read-file!", "Reads the contents of a file and returns it as a string."- , oneArg "read-file!" $ \case+ , oneArg "read-file" $ \caseString filename -> readFileS filename >>= \caseLeft err -> throwErrorHere . OtherError $ "Error reading file: " <> errRight text -> pure $ String text@@ -162,7 +176,7 @@ replPrimFns = fromList $ allDocs $String filename -> readFileS filename >>= \caseLeft err -> throwErrorHere . OtherError $ "Error reading file: " <> errRight text -> interpretMany ("[load! " <> filename <> "]") text- _ -> throwErrorHere $ TypeError "load!: expects a string"+ _ -> throwErrorHere $ TypeError "load: expects a string"), ( "gen-key-pair!", "Given an elliptic curve, generates a cryptographic key-pair. Use\diff --git a/src/Radicle/Internal/Effects/Capabilities.hs b/src/Radicle/Internal/Effects/Capabilities.hsindex 4f2b12e..f053461 100644--- a/src/Radicle/Internal/Effects/Capabilities.hs+++ b/src/Radicle/Internal/Effects/Capabilities.hs@@ -7,7 +7,6 @@ module Radicle.Internal.Effects.Capabilities whereimport Protolude-import qualified Data.Map as Mapimport Data.Text.Prettyprint.Doc (PageWidth)import Data.Timeimport System.Console.Haskeline hiding (catch)@@ -18,30 +17,19 @@ import GHCJS.DOM.XMLHttpRequest#endifimport Radicle.Internal.Core-import qualified Radicle.Internal.Input as Inputclass (Monad m) => Stdin m wheregetLineS :: m (Maybe Text) -- gives Nothing on EOF- getLineCompletionS :: [Text] -> m (Maybe Text)instance {-# OVERLAPPABLE #-} Stdin m => Stdin (Lang m) wheregetLineS = lift getLineS- getLineCompletionS = lift . getLineCompletionSinstance Stdin IO wheregetLineS = dodone <- isEOFif donethen pure Nothingelse Just <$> getLine- getLineCompletionS _ = getLineS-instance (Input.MonadException m) => Stdin (Input.InputT m) where- getLineS = Input.getInputLine Input.noCompletions "rad> "- getLineCompletionS compl = Input.getInputLine (radicleCompletion compl) "rad> "---radicleCompletion :: (Monad m) => [Text] -> Input.Completions m-radicleCompletion = Input.wordCompletions ['(', ')', ' ', '\n'] . (specials <>)- where- specials = fromIdent <$> Map.keys (specialForms @Identity)+instance (MonadException m) => Stdin (InputT m) where+ getLineS = (fmap.fmap) toS (getInputLine "rad> ")class (Monad m) => Stdout m whereputStrS :: Text -> m ()@@ -49,8 +37,8 @@ instance {-# OVERLAPPABLE #-} Stdout m => Stdout (Lang m) whereputStrS = lift . putStrSinstance Stdout IO whereputStrS = putStrLn-instance (Input.MonadException m, Monad m) => Stdout (Input.InputT m) where- putStrS = Input.outputStrLn . toS+instance (MonadException m, Monad m) => Stdout (InputT m) where+ putStrS = outputStrLn . toSclass (Monad m) => Exit m whereexitS :: m ()@@ -87,7 +75,7 @@ class (Monad m) => SetSubs m whereclass (Monad m) => ReadFile m wherereadFileS :: Text -> m (Either Text Text) -- ^ Left error or Right contents#ifdef ghcjs_HOST_OS-instance ReadFile (Input.InputT IO) where+instance ReadFile (InputT IO) wherereadFileS = lift . requestFilewhererequestFile :: Text -> IO (Either Text Text)@@ -100,12 +88,11 @@ instance ReadFile (Input.InputT IO) whereNothing -> Left "no response from server"Just v -> Right v#else+instance ReadFile (InputT IO) where+ readFileS = lift . readFileSinstance ReadFile IO wherereadFileS fname = (Right <$> readFile (toS fname))`catch` (\(e :: IOException) -> pure (Left (show e)))-instance ReadFile (Input.InputT IO) where- readFileS fname = lift $ (Right <$> readFile (toS fname))- `catch` (\(e :: IOException) -> pure (Left (show e)))#endifinstance {-# OVERLAPPABLE #-} ReadFile m => ReadFile (Lang m) wherereadFileS = lift . readFileSdiff --git a/src/Radicle/Internal/Input.hs b/src/Radicle/Internal/Input.hsdeleted file mode 100644index a72305b..0000000--- a/src/Radicle/Internal/Input.hs+++ /dev/null@@ -1,61 +0,0 @@--- | Haskeline-style wrapper, since it doesn't *quite* provide the right API--- (completion functions cannot be dynamically modified). It will also enable--- a nice abstraction barrier for REPL UI features.--module Radicle.Internal.Input- ( InputT- , Completions- , noCompletions- , wordCompletions- , getInputLine- , runInputT- , outputStrLn-- , MonadException- )-where--import Protolude--import Control.Monad.Trans (MonadTrans(..))-import qualified Data.Text as T-import System.Console.Haskeline (MonadException)-import qualified System.Console.Haskeline as H--newtype InputT m a = InputT { unInputT :: H.InputT (ReaderT (Completions m) m) a }- deriving (Functor, Applicative, Monad)--instance MonadTrans InputT where- lift = InputT . lift . lift--instance (MonadIO m) => MonadIO (InputT m) where- liftIO = lift . liftIO--newtype Completions m = Completions { getCompletions :: H.CompletionFunc (ReaderT (Completions m) m) }--noCompletions :: (Monad m) => Completions m-noCompletions = Completions H.noCompletion--wordCompletions :: (Monad m) => [Char] -> [Text] -> Completions m-wordCompletions whitespace words = Completions $ H.completeWord Nothing whitespace go- where- go s = pure . fmap H.simpleCompletion- . filter (s `isPrefixOf`)- $ map T.unpack words-{-# ANN module ("HLint: ignore Use String" :: [Char]) #-}--getInputLine :: (Monad m, MonadException m) => Completions m -> Text -> InputT m (Maybe Text)-getInputLine compl prompt = InputT $- (fmap.fmap) toS $ H.mapInputT (local (const compl)) (H.getInputLine (T.unpack prompt))--runInputT :: (MonadException m) => Maybe FilePath -> InputT m a -> m a-runInputT histfile = (`runReaderT` noCompletions)- . H.runInputT (H.setComplete dynamicCompletion H.defaultSettings { H.historyFile = histfile })- . unInputT- where- dynamicCompletion cx = do- compl <- ask- getCompletions compl cx--outputStrLn :: (MonadIO m) => Text -> InputT m ()-outputStrLn = InputT . H.outputStrLn . T.unpackdiff --git a/src/Radicle/Internal/PrimFns.hs b/src/Radicle/Internal/PrimFns.hsindex aa8d378..ed286f2 100644--- a/src/Radicle/Internal/PrimFns.hs+++ b/src/Radicle/Internal/PrimFns.hs@@ -203,7 +203,7 @@ purePrimFns = fromList $ allDocs $[Number n, vs] -> case Num.isInt n ofLeft _ -> throwErrorHere $ OtherError "nth: first argument was not an integer"Right i -> do- xs <- hoistEitherWith (const (toLangError . OtherError $ "nth: second argument must be sequential")) $ fromRad vs+ xs <- hoistEitherWith (const (toLangError . OtherError $ "nth: first argument must be sequential")) $ fromRad vscase xs `atMay` i ofJust x -> pure xNothing -> throwErrorHere $ OtherError "nth: index out of bounds"diff --git a/test/spec/Radicle/Internal/TestCapabilities.hs b/test/spec/Radicle/Internal/TestCapabilities.hsindex 6c80b8d..e9b405b 100644--- a/test/spec/Radicle/Internal/TestCapabilities.hs+++ b/test/spec/Radicle/Internal/TestCapabilities.hs@@ -138,7 +138,6 @@ instance {-# OVERLAPPING #-} Stdin TestLang wherecase worldStateStdin ws of[] -> pure Nothingh:hs -> lift (put $ ws { worldStateStdin = hs }) >> pure (Just h)- getLineCompletionS _ = getLineSinstance {-# OVERLAPPING #-} Stdout TestLang whereputStrS t = lift $diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hsindex c25c482..4d35084 100644--- a/test/spec/Radicle/Tests.hs+++ b/test/spec/Radicle/Tests.hs@@ -353,7 +353,7 @@ test_eval =, testCase "'catch' catches thrown exceptions" $ dolet prog = [s|- (catch (quote exc) (throw (quote exc) #t) (fn [y stack] y))+ (catch (quote exc) (throw (quote exc) #t) (fn [y] y))|]prog `succeedsWith` Boolean True@@ -361,13 +361,13 @@ test_eval =let prog = [s|(def t #t)(def f #f)- (catch (quote exc) (throw (quote exc) f) (fn [y stack] t))+ (catch (quote exc) (throw (quote exc) f) (fn [y] t))|]prog `succeedsWith` Boolean True, testCase "'catch 'any' catches any exception" $ dolet prog = [s|- (catch 'any (throw (quote exc) #f) (fn [y stack] #t))+ (catch 'any (throw (quote exc) #f) (fn [y] #t))|]prog `succeedsWith` Boolean True@@ -619,7 +619,7 @@ test_repl_primops =, testCase "catch catches read-line errors" $ dolet prog = [s|- (catch 'any (read-line!) (fn [x stack] "caught"))+ (catch 'any (read-line!) (fn [x] "caught"))|]input = ["\"blah"]res = run input prog