Skip to content

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.yaml
index 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.yaml
index ede97e9..a4cc491 100644
--- a/.stylish-haskell.yaml
+++ b/.stylish-haskell.yaml
@@ -200,6 +200,5 @@ language_extensions:
- ScopedTypeVariables
- StandaloneDeriving
- TupleSections
- - TypeApplications
- TypeFamilies
- TypeOperators
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index 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 same
associations 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/Output
Effectful 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.hs
index df2c848..50d336c 100644
--- a/exe/Doc.hs
+++ b/exe/Doc.hs
@@ -7,7 +7,7 @@ import Protolude
import qualified Data.Text as T
import Options.Applicative
import Radicle
-import qualified Radicle.Internal.Input as Input
+import System.Console.Haskeline (defaultSettings, runInputT)
import Text.Pandoc
main :: IO ()
@@ -25,7 +25,7 @@ run :: FilePath -> IO ()
run f = do
txt <- readFile f
pand <- runIOorExplode $ readMarkdown def txt
- res <- Input.runInputT Nothing $ runLang replBindings $ interpretMany (toS f) $ getCode pand
+ res <- runInputT defaultSettings $ runLang replBindings $ interpretMany (toS f) $ getCode pand
case res of
(Left err, _) -> die . toS $ "Error: " ++ show err
_ -> pure ()
diff --git a/exe/RadicleExe.hs b/exe/RadicleExe.hs
index 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 Radicle
import Servant.Client
+import System.Console.Haskeline (InputT)
import System.Directory (doesFileExist)
-import qualified Radicle.Internal.Input as Input
import qualified Radicle.Internal.Number as Num
import 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]
where
sendPrimop =
diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hs
index 370dbd6..46fd96e 100644
--- a/exe/ReferenceDoc.hs
+++ b/exe/ReferenceDoc.hs
@@ -11,12 +11,12 @@ import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import qualified GHC.Exts as GhcExts
import Radicle
-import qualified Radicle.Internal.Input as Input
+import System.Console.Haskeline (defaultSettings, runInputT)
import Text.Pandoc
main :: 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 = do
seqs = ["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.yaml
index 0c28568..522efd6 100644
--- a/package.yaml
+++ b/package.yaml
@@ -205,6 +205,5 @@ default-extensions:
- ScopedTypeVariables
- StandaloneDeriving
- TupleSections
-- TypeApplications
- TypeFamilies
- TypeOperators
diff --git a/rad/prelude.rad b/rad/prelude.rad
index 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.rad
index 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.rad
index 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.rad
index 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.rad
index 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.rad
index 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 eval
diff --git a/rad/repl.rad b/rad/repl.rad
index 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.sh
index 6929023..4eb9216 100755
--- a/scripts/ci-tests.sh
+++ b/scripts/ci-tests.sh
@@ -6,7 +6,7 @@
set -e -x
BASEDIR=$(dirname $BASH_SOURCE)/..
cd $BASEDIR
-./scripts/hottags.sh
+hothasktags -XLambdaCase -XTypeFamilies -XScopedTypeVariables -XFunctionalDependencies -XTupleSections -XExplicitNamespaces -XStandaloneDeriving -XDefaultSignatures -R src > TAGS
stack exec hlint .
./scripts/check-fmt.sh
stack test --fast
diff --git a/scripts/hottags.sh b/scripts/hottags.sh
index 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 > TAGS
diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hs
index befdf1e..1261749 100644
--- a/src/Radicle/Internal/Core.hs
+++ b/src/Radicle/Internal/Core.hs
@@ -26,7 +26,6 @@ import qualified Data.Sequence as Seq
import Generics.Eot
import qualified GHC.Exts as GhcExts
import 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 l
handlerclo <- baseEval handler
case 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 e
if 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) where
instance CPA t => FromRad t Rational where
fromRad (Number n) = pure n
fromRad _ = 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 where
fromRad = fromRad >=> Num.isSci
instance 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 Value
callFn f vs = case f of
Lambda bnds body closure ->
diff --git a/src/Radicle/Internal/Effects.hs b/src/Radicle/Internal/Effects.hs
index 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 Time
import GHC.Exts (IsList(..))
+import System.Console.Haskeline
+ ( CompletionFunc
+ , InputT
+ , completeWord
+ , defaultSettings
+ , historyFile
+ , runInputT
+ , setComplete
+ , simpleCompletion
+ )
import Radicle.Internal.Core
import Radicle.Internal.Crypto
import Radicle.Internal.Effects.Capabilities
-import qualified Radicle.Internal.Input as Input
import Radicle.Internal.Interpret
import Radicle.Internal.Pretty
import 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) where
getRandomBytes = liftIO . getRandomBytes
instance MonadRandom m => MonadRandom (LangT (Bindings (PrimFns m)) m) where
getRandomBytes = lift . getRandomBytes
-instance UUID.MonadUUID (Input.InputT IO) where
+instance UUID.MonadUUID (InputT IO) where
uuid = liftIO UUID.uuid
instance UUID.MonadUUID m => UUID.MonadUUID (LangT (Bindings (PrimFns m)) m) where
uuid = 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 preCode
case r of
@@ -48,17 +59,31 @@ repl histFile preFileName preCode bindings = do
Left e -> putDoc $ pretty e
Right () -> 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 pureEnv
replPrimFns :: ReplM m => PrimFns m
replPrimFns = 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" $ \case
String filename -> readFileS filename >>= \case
Left err -> throwErrorHere . OtherError $ "Error reading file: " <> err
Right text -> pure $ String text
@@ -162,7 +176,7 @@ replPrimFns = fromList $ allDocs $
String filename -> readFileS filename >>= \case
Left err -> throwErrorHere . OtherError $ "Error reading file: " <> err
Right 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.hs
index 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 where
import Protolude
-import qualified Data.Map as Map
import Data.Text.Prettyprint.Doc (PageWidth)
import Data.Time
import System.Console.Haskeline hiding (catch)
@@ -18,30 +17,19 @@ import GHCJS.DOM.XMLHttpRequest
#endif
import Radicle.Internal.Core
-import qualified Radicle.Internal.Input as Input
class (Monad m) => Stdin m where
getLineS :: m (Maybe Text) -- gives Nothing on EOF
- getLineCompletionS :: [Text] -> m (Maybe Text)
instance {-# OVERLAPPABLE #-} Stdin m => Stdin (Lang m) where
getLineS = lift getLineS
- getLineCompletionS = lift . getLineCompletionS
instance Stdin IO where
getLineS = do
done <- isEOF
if done
then pure Nothing
else 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 where
putStrS :: Text -> m ()
@@ -49,8 +37,8 @@ instance {-# OVERLAPPABLE #-} Stdout m => Stdout (Lang m) where
putStrS = lift . putStrS
instance Stdout IO where
putStrS = 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 . toS
class (Monad m) => Exit m where
exitS :: m ()
@@ -87,7 +75,7 @@ class (Monad m) => SetSubs m where
class (Monad m) => ReadFile m where
readFileS :: Text -> m (Either Text Text) -- ^ Left error or Right contents
#ifdef ghcjs_HOST_OS
-instance ReadFile (Input.InputT IO) where
+instance ReadFile (InputT IO) where
readFileS = lift . requestFile
where
requestFile :: Text -> IO (Either Text Text)
@@ -100,12 +88,11 @@ instance ReadFile (Input.InputT IO) where
Nothing -> Left "no response from server"
Just v -> Right v
#else
+instance ReadFile (InputT IO) where
+ readFileS = lift . readFileS
instance ReadFile IO where
readFileS 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)))
#endif
instance {-# OVERLAPPABLE #-} ReadFile m => ReadFile (Lang m) where
readFileS = lift . readFileS
diff --git a/src/Radicle/Internal/Input.hs b/src/Radicle/Internal/Input.hs
deleted file mode 100644
index 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.unpack
diff --git a/src/Radicle/Internal/PrimFns.hs b/src/Radicle/Internal/PrimFns.hs
index 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 of
Left _ -> 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 vs
case xs `atMay` i of
Just x -> pure x
Nothing -> throwErrorHere $ OtherError "nth: index out of bounds"
diff --git a/test/spec/Radicle/Internal/TestCapabilities.hs b/test/spec/Radicle/Internal/TestCapabilities.hs
index 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 where
case worldStateStdin ws of
[] -> pure Nothing
h:hs -> lift (put $ ws { worldStateStdin = hs }) >> pure (Just h)
- getLineCompletionS _ = getLineS
instance {-# OVERLAPPING #-} Stdout TestLang where
putStrS t = lift $
diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hs
index 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" $ do
let 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" $ do
let 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" $ do
let prog = [s|
- (catch 'any (read-line!) (fn [x stack] "caught"))
+ (catch 'any (read-line!) (fn [x] "caught"))
|]
input = ["\"blah"]
res = run input prog