Skip to content

A peer-to-peer stack for code collaboration

Review fixes

Julian K. Arni96bd8562520c
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 3c382dd..f4ac73e 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -7,7 +7,7 @@ jobs:
- checkout
- restore_cache:
keys:
- - stack-work-v1-{{ checksum "stack.yaml" }}-{{ checksum "radicle.cabal" }}
+ - stack-work-v1-{{ checksum "stack.yaml" }}-{{ checksum "package.yaml" }}
# If an exact match is unavailable, use the most recent one
- stack-work-v1-
paths:
@@ -19,6 +19,6 @@ jobs:
name: Test
command: stack test --pedantic --no-terminal --fast
- save_cache:
- key: stack-work-v1-{{ checksum "stack.yaml" }}-{{ checksum "radicle.cabal" }}
+ key: stack-work-v1-{{ checksum "stack.yaml" }}-{{ checksum "package.yaml" }}
paths:
- ~/.stack
diff --git a/.gitignore b/.gitignore
index f44ee4b..072b493 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
dist
cabal-dev
+radicle.cabal
*.o
*.hi
*.chi
diff --git a/package.yaml b/package.yaml
index 2e47925..143bc3d 100644
--- a/package.yaml
+++ b/package.yaml
@@ -12,7 +12,6 @@ dependencies:
- base >=4 && <5
- containers
- haskeline
-- lens
- megaparsec
- mmorph
- mtl
@@ -53,9 +52,8 @@ tests:
executables:
repl:
- main: Repl.hs
- source-dirs:
- - exe
+ main: Main.hs
+ source-dirs: repl
dependencies:
- radicle
ghc-options: -Wall -threaded
diff --git a/radicle.cabal b/radicle.cabal
deleted file mode 100644
index c7e150f..0000000
--- a/radicle.cabal
+++ /dev/null
@@ -1,127 +0,0 @@
--- This file has been generated from package.yaml by hpack version 0.20.0.
---
--- see: https://github.com/sol/hpack
---
--- hash: b5ccc8731a18aa5cabe0cb961e8822afbf3fcf733448169921e2052611053d81
-
-name: radicle
-version: 0.0.0
-author: Monadic <[email protected]>
-maintainer: Monadic <[email protected]>
-license: BSD3
-license-file: LICENSE
-build-type: Simple
-cabal-version: >= 1.10
-
-extra-source-files:
- ChangeLog.md
- README.md
-
-source-repository head
- type: git
- location: oscoin/radicle
-
-library
- hs-source-dirs:
- src
- default-extensions: AutoDeriveTypeable ConstraintKinds DeriveDataTypeable DeriveFunctor DeriveGeneric FlexibleContexts FlexibleInstances FunctionalDependencies GeneralizedNewtypeDeriving MultiParamTypeClasses OverloadedStrings RankNTypes RecordWildCards TupleSections TypeFamilies TypeOperators
- ghc-options: -Wall
- build-depends:
- base >=4 && <5
- , containers
- , haskeline
- , lens
- , megaparsec
- , mmorph
- , mtl
- , prettyprinter
- , text
- exposed-modules:
- Radicle
- Radicle.Internal
- Radicle.Internal.Core
- Radicle.Internal.Parse
- Radicle.Internal.Pretty
- Radicle.Internal.Subscriber
- Radicle.Internal.Subscriber.Capabilities
- other-modules:
- Paths_radicle
- default-language: Haskell2010
-
-executable repl
- main-is: Repl.hs
- hs-source-dirs:
- exe
- default-extensions: AutoDeriveTypeable ConstraintKinds DeriveDataTypeable DeriveFunctor DeriveGeneric FlexibleContexts FlexibleInstances FunctionalDependencies GeneralizedNewtypeDeriving MultiParamTypeClasses OverloadedStrings RankNTypes RecordWildCards TupleSections TypeFamilies TypeOperators
- ghc-options: -Wall -threaded
- build-depends:
- base >=4 && <5
- , containers
- , haskeline
- , lens
- , megaparsec
- , mmorph
- , mtl
- , prettyprinter
- , radicle
- , text
- other-modules:
- Paths_radicle
- default-language: Haskell2010
-
-test-suite doctest
- type: exitcode-stdio-1.0
- main-is: Main.hs
- hs-source-dirs:
- test/docs
- default-extensions: AutoDeriveTypeable ConstraintKinds DeriveDataTypeable DeriveFunctor DeriveGeneric FlexibleContexts FlexibleInstances FunctionalDependencies GeneralizedNewtypeDeriving MultiParamTypeClasses OverloadedStrings RankNTypes RecordWildCards TupleSections TypeFamilies TypeOperators
- ghc-options: -Wall -threaded
- build-depends:
- Glob
- , base >=4 && <5
- , containers
- , doctest
- , haskeline
- , hpack
- , lens
- , megaparsec
- , mmorph
- , mtl
- , prettyprinter
- , radicle
- , text
- other-modules:
- Paths_radicle
- default-language: Haskell2010
-
-test-suite spec
- type: exitcode-stdio-1.0
- main-is: Main.hs
- hs-source-dirs:
- test/spec
- default-extensions: AutoDeriveTypeable ConstraintKinds DeriveDataTypeable DeriveFunctor DeriveGeneric FlexibleContexts FlexibleInstances FunctionalDependencies GeneralizedNewtypeDeriving MultiParamTypeClasses OverloadedStrings RankNTypes RecordWildCards TupleSections TypeFamilies TypeOperators
- ghc-options: -Wall -threaded
- build-depends:
- QuickCheck
- , base >=4 && <5
- , containers
- , haskeline
- , lens
- , megaparsec
- , mmorph
- , mtl
- , prettyprinter
- , quickcheck-instances
- , radicle
- , string-qq
- , tasty
- , tasty-discover
- , tasty-hunit
- , tasty-quickcheck
- , text
- other-modules:
- Radicle.Internal.Arbitrary
- Radicle.Internal.TestCapabilities
- Radicle.Tests
- Paths_radicle
- default-language: Haskell2010
diff --git a/exe/Repl.hs b/repl/Main.hs
similarity index 100%
rename from exe/Repl.hs
rename to repl/Main.hs
diff --git a/config.rad b/repl/config.rad
similarity index 100%
rename from config.rad
rename to repl/config.rad
diff --git a/src/Radicle.hs b/src/Radicle.hs
index c78aafa..3a8b8fc 100644
--- a/src/Radicle.hs
+++ b/src/Radicle.hs
@@ -19,17 +19,15 @@ module Radicle
, ($$)
, Ident
, fromIdent
- , makeIdent
+ , mkIdent
, Env(..)
, pureEmptyEnv
, Lang
- , runLangM
- , runLangT
- , Bindings
+ , runLang
+ , Bindings(..)
, replBindings
- -- ** Core lenses
- , HasEnv(..)
- , HasPrimops(..)
+ -- ** Re-exports
+ , runIdentity
-- * Parsing
, parse
@@ -46,5 +44,7 @@ module Radicle
, repl
) where
+import Control.Monad.Identity (runIdentity)
import Data.Text.Prettyprint.Doc
import Radicle.Internal
+
diff --git a/src/Radicle/Internal.hs b/src/Radicle/Internal.hs
index d4615d9..3eeefef 100644
--- a/src/Radicle/Internal.hs
+++ b/src/Radicle/Internal.hs
@@ -1,6 +1,6 @@
module Radicle.Internal
( module X
- , makeIdent
+ , mkIdent
) where
import Radicle.Internal.Core as X
@@ -13,7 +13,7 @@ import Data.Text (Text)
import qualified Text.Megaparsec as M
-- | Smart constructor for Ident.
-makeIdent :: Text -> Maybe Ident
-makeIdent t = case runReader (M.runParserT identP "" t) [] of
+mkIdent :: Text -> Maybe Ident
+mkIdent t = case runReader (M.runParserT identP "" t) [] of
Left _ -> Nothing
Right v -> pure v
diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hs
index 33958b9..954ae2a 100644
--- a/src/Radicle/Internal/Core.hs
+++ b/src/Radicle/Internal/Core.hs
@@ -3,11 +3,8 @@
{-# LANGUAGE UndecidableInstances #-}
module Radicle.Internal.Core where
-import Control.Lens (At(..), Index, IxValue, Ixed(..), makeFields,
- makePrisms, (%~), (&), (<&>), (^.), (.=))
import Control.Monad.Except (ExceptT(..), MonadError, runExceptT,
throwError)
-import Control.Monad.Identity (Identity, runIdentity)
import Control.Monad.State
import Data.Bifunctor (first)
import Data.Data (Data)
@@ -73,54 +70,37 @@ instance IsList Env where
fromList = Env . fromList
toList = GHC.Exts.toList . fromEnv
-type instance Index Env = Ident
-type instance IxValue Env = Value
-
-instance Ixed Env
-instance At Env where
- at k f (Env m) = f mv <&> \r -> Env $ case r of
- Nothing -> maybe m (const (Map.delete k m)) mv
- Just v' -> Map.insert k v' m
- where mv = Map.lookup k m
-
--- Primop mappings
-type Prims m = Map Ident ([Value] -> LangT (Bindings m) m Value)
+-- | Primop mappings. The parameter specifies the monad the primops run in.
+type Primops m = Map Ident ([Value] -> LangT (Bindings m) m Value)
-- | Bindings, either from the env or from the primops.
data Bindings m = Bindings
- { _bindingsEnv :: Env
- , _bindingsPrimops :: Prims m
+ { bindingsEnv :: Env
+ , bindingsPrimops :: Primops m
} deriving (Generic)
-- | The environment in which expressions are evaluated.
newtype LangT r m a = LangT
- { fromLangM :: ExceptT LangError (StateT r m) a }
- deriving ( Functor, Applicative, Monad, MonadError LangError, MonadState r)
+ { fromLangT :: ExceptT LangError (StateT r m) a }
+ deriving (Functor, Applicative, Monad, MonadError LangError, MonadState r)
instance MonadTrans (LangT r) where lift = LangT . lift . lift
+-- | A monad for language operations specialized to have as state the Bindings
+-- with appropriate underlying monad.
type Lang m = LangT (Bindings m) m
-runLangM :: Bindings Identity -> Lang Identity a -> Either LangError a
-runLangM e l = runIdentity $ runLangT e l
-
-runLangT :: Monad m => Bindings m -> Lang m a -> m (Either LangError a)
-runLangT e l = evalStateT (runExceptT $ fromLangM l) e
+runLang :: Monad m => Bindings m -> Lang m a -> m (Either LangError a)
+runLang e l = evalStateT (runExceptT $ fromLangT l) e
+-- | Like 'local' or 'withState'
withEnv :: Monad m => (Bindings m -> Bindings m) -> Lang m a -> Lang m a
-withEnv f a = do
- x <- get
- modify f
- r <- a
- put x
- pure r
-
--- * Lenses
-
-makeFields ''Bindings
-makePrisms ''Value
-makePrisms ''LangError
-
+withEnv modifier action = do
+ oldEnv <- get
+ modify modifier
+ res <- action
+ put oldEnv
+ pure res
-- * Functions
@@ -130,19 +110,23 @@ pureEmptyEnv = Bindings mempty purePrimops
-- | Lookup an atom in the environment
lookupAtom :: Monad m => Ident -> Lang m Value
-lookupAtom i = get >>= \e -> case e ^. env . at i of
+lookupAtom i = get >>= \e -> case Map.lookup i . fromEnv $ bindingsEnv e of
Nothing -> throwError $ UnknownIdentifier i
Just v -> pure v
-- | Lookup a primop.
lookupPrimop :: Monad m => Ident -> Lang m ([Value] -> Lang m Value)
-lookupPrimop i = get >>= \e -> case e ^. primops . at i of
+lookupPrimop i = get >>= \e -> case Map.lookup i $ bindingsPrimops e of
Nothing -> throwError $ Impossible "Unknown primop"
Just v -> pure v
+defineAtom :: Monad m => Ident -> Value -> Lang m ()
+defineAtom i v = modify (\e -> e
+ { bindingsEnv = Env . Map.insert i v . fromEnv $ bindingsEnv e })
+
-- | The universal primops. These are available in chain evaluation, and are
-- not shadowable via 'define'.
-purePrimops :: Monad m => Prims m
+purePrimops :: Monad m => Primops m
purePrimops = Map.fromList $ first identFromString <$>
[ ("eval", \args -> case args of
[List (v:vs)] -> eval (Apply v vs)
@@ -156,7 +140,7 @@ purePrimops = Map.fromList $ first identFromString <$>
, ("define", \args -> case args of
[Atom name, val] -> do
val' <- eval val
- env . at name .= Just val'
+ defineAtom name val'
pure $ List [Atom $ identFromString "set!", Atom name, val']
[_, _] -> throwError $ OtherError "define expects atom for first arg"
xs -> throwError $ WrongNumberOfArgs "define" 2 (length xs))
@@ -198,13 +182,13 @@ eval val = case val of
"lambda should already have an env"
Lambda bnds body (Just closure) -> do
vs' <- traverse eval vs
- let mappings = GHC.Exts.fromList (zip bnds vs')
- modEnv = const $ mappings <> closure
- withEnv (\e -> e & env %~ modEnv) (eval body)
+ let mappings = fromList (zip bnds vs')
+ modEnv = mappings <> closure
+ withEnv (\e -> e { bindingsEnv = modEnv }) (eval body)
_ -> throwError $ TypeError "Trying to apply a non-function"
Primop i -> pure $ Primop i
e@(Lambda _ _ (Just _)) -> pure e
- Lambda args body Nothing -> gets $ \e -> Lambda args body (Just $ e ^. env)
+ Lambda args body Nothing -> gets $ Lambda args body . Just . bindingsEnv
SortedMap mp -> do
let evalSnd (a,b) = (a ,) <$> eval b
SortedMap . Map.fromList <$> traverse evalSnd (Map.toList mp)
diff --git a/src/Radicle/Internal/Parse.hs b/src/Radicle/Internal/Parse.hs
index 2b4c07d..fdd3b3a 100644
--- a/src/Radicle/Internal/Parse.hs
+++ b/src/Radicle/Internal/Parse.hs
@@ -2,7 +2,6 @@
module Radicle.Internal.Parse where
import Control.Applicative (many, (<|>))
-import Control.Lens ((^.))
import Control.Monad (void)
import Control.Monad.Except
import Control.Monad.Identity (Identity)
@@ -122,22 +121,22 @@ valueP = do
-- >>> interpret "test" "(#t #f)" pureEmptyEnv
-- Left (TypeError "Trying to apply a non-function")
interpret :: Monad m => String -> Text -> Bindings m -> m (Either LangError Value)
-interpret sourceName expr re = do
- let primopNames = Map.keys (re ^. primops)
+interpret sourceName expr bnds = do
+ let primopNames = Map.keys (bindingsPrimops bnds)
parsed = runReader (runParserT valueP sourceName expr) primopNames
case parsed of
Left e -> pure . Left $ ParseError e
- Right v -> runLangT re $ eval v
+ Right v -> runLang bnds $ eval v
-- | Parse and evaluate a Text as multiple expressions.
--
-- Examples:
--
--- >>> runLangM pureEmptyEnv $ interpretMany "test" "(define id (lambda (x) x))\n(id #t)"
+-- >>> runLang pureEmptyEnv $ interpretMany "test" "(define id (lambda (x) x))\n(id #t)"
-- Right (Boolean True)
interpretMany :: Monad m => String -> Text -> Lang m Value
interpretMany sourceName src = do
- primopNames <- gets $ \re -> Map.keys (re ^. primops)
+ primopNames <- gets $ Map.keys . bindingsPrimops
let parsed = parseValues sourceName src primopNames
case partitionEithers parsed of
([], vs) -> last <$> mapM eval vs
@@ -182,7 +181,7 @@ parse file src ids = do
-- | Like 'parse', but uses "(test)" as the source name and the default set of
-- primops.
parseTest :: MonadError String m => Text -> m Value
-parseTest t = parse "(test)" t (Map.keys $ e ^. primops)
+parseTest t = parse "(test)" t (Map.keys $ bindingsPrimops e)
where
e :: Bindings (Lang Identity)
e = pureEmptyEnv
diff --git a/src/Radicle/Internal/Subscriber.hs b/src/Radicle/Internal/Subscriber.hs
index 1d54b04..4f7fcba 100644
--- a/src/Radicle/Internal/Subscriber.hs
+++ b/src/Radicle/Internal/Subscriber.hs
@@ -1,12 +1,12 @@
{-# LANGUAGE ScopedTypeVariables #-}
module Radicle.Internal.Subscriber where
-import Control.Lens (at, (&), (<>~), (?~), (^.))
import Control.Monad.Except
import Control.Monad.State (gets)
import Data.Bifunctor (first)
import Data.Either
import qualified Data.Map as Map
+import Data.Monoid ((<>))
import Data.Text (Text)
import System.Console.Haskeline
@@ -20,14 +20,17 @@ type ReplM m = (Stdout m, Stdin m, GetEnv (Lang m), SetEnv (Lang m))
repl :: Text -> IO ()
repl preCode = do
r <- runInputT defaultSettings
- $ runLangT replBindings
+ $ runLang replBindings
$ interpretMany "[pre]" preCode
print r
-replBindings :: ReplM m => Bindings m
-replBindings = pureEmptyEnv & primops <>~ replPrimops
+replBindings :: forall m. ReplM m => Bindings m
+replBindings = e { bindingsPrimops = bindingsPrimops e <> replPrimops }
+ where
+ e :: Bindings m
+ e = pureEmptyEnv
-replPrimops :: forall m. ReplM m => Prims m
+replPrimops :: forall m. ReplM m => Primops m
replPrimops = Map.fromList $ first identFromString <$>
[ ("print!", \args -> case args of
[x] -> do
@@ -39,7 +42,7 @@ replPrimops = Map.fromList $ first identFromString <$>
, ("set-env!", \args -> case args of
[Atom x, v] -> do
v' <- eval v
- modifyEnvS (\e -> e & at x ?~ v')
+ defineAtom x v'
pure nil
[_, _] -> throwError $ TypeError "Expected atom as first arg"
xs -> throwError $ WrongNumberOfArgs "set-env!" 2 (length xs))
@@ -47,7 +50,7 @@ replPrimops = Map.fromList $ first identFromString <$>
, ("get-line!", \args -> case args of
[] -> do
ln <- getLineS
- allPrims <- gets (^. primops)
+ allPrims <- gets bindingsPrimops
let p = parseValues "[stdin]" ln (Map.keys allPrims)
case partitionEithers p of
([], results) -> pure $ List results
@@ -59,7 +62,7 @@ replPrimops = Map.fromList $ first identFromString <$>
x' <- eval x
v' <- eval v
case (x', v') of
- (SortedMap m, fn) -> case m ^. at (identFromString "getter") of
+ (SortedMap m, fn) -> case Map.lookup (identFromString "getter") m of
Nothing -> throwError
$ OtherError "subscribe-to!: Expected 'getter' key"
Just g -> go
diff --git a/src/Radicle/Internal/Subscriber/Capabilities.hs b/src/Radicle/Internal/Subscriber/Capabilities.hs
index 090596d..29f5853 100644
--- a/src/Radicle/Internal/Subscriber/Capabilities.hs
+++ b/src/Radicle/Internal/Subscriber/Capabilities.hs
@@ -4,8 +4,7 @@
-- constraints) what effects they do.
module Radicle.Internal.Subscriber.Capabilities where
-import Control.Lens ((.=))
-import Control.Monad.State (gets)
+import Control.Monad.State (gets, modify)
import Control.Monad.Trans
import Data.Text (Text)
import qualified Data.Text as T
@@ -14,32 +13,47 @@ import System.Console.Haskeline
import Radicle.Internal.Core
-class (Monad m) => Stdin m where getLineS :: m Text
-instance Stdin m => Stdin (Lang m) where getLineS = lift getLineS
+class (Monad m) => Stdin m where
+ getLineS :: m Text
+instance Stdin m => Stdin (Lang m) where
+ getLineS = lift getLineS
instance (MonadException m, Monad m) => Stdin (InputT m) where
getLineS = getInputLine "rad> " >>= \x -> case x of
Nothing -> error "curious about why this would happen"
Just v -> pure $ T.pack v
-class (Monad m) => Stdout m where putStrS :: Text -> m ()
-instance Stdout m => Stdout (Lang m) where putStrS = lift . putStrS
+class (Monad m) => Stdout m where
+ putStrS :: Text -> m ()
+instance Stdout m => Stdout (Lang m) where
+ putStrS = lift . putStrS
instance (MonadException m, Monad m) => Stdout (InputT m) where
putStrS = outputStrLn . T.unpack
-class (Monad m) => Exit m where exitS :: m ()
-instance Exit m => Exit (Lang m) where exitS = lift exitS
-
-class (Monad m) => GetEnv m where getEnvS :: m Env
-instance Monad m => GetEnv (Lang m) where getEnvS = gets _bindingsEnv
-instance GetEnv m => GetEnv (InputT m) where getEnvS = lift getEnvS
-
-class (Monad m) => SetEnv m where setEnvS :: Env -> m ()
-instance Monad m => SetEnv (Lang m) where setEnvS e = env .= e
-
-class (Monad m) => GetSourceName m where getSourceNameS :: m String
-class (Monad m) => HasPageWidth m where getPageWidthS :: m PageWidth
-class (Monad m) => GetSubs m where getSubsS :: m [(Text, Value -> m ())]
-class (Monad m) => SetSubs m where setSubS :: Text -> (Value -> m ()) -> m ()
+class (Monad m) => Exit m where
+ exitS :: m ()
+instance Exit m => Exit (Lang m) where
+ exitS = lift exitS
+
+class (Monad m) => GetEnv m where
+ getEnvS :: m Env
+instance Monad m => GetEnv (Lang m) where
+ getEnvS = gets bindingsEnv
+instance GetEnv m => GetEnv (InputT m) where
+ getEnvS = lift getEnvS
+
+class (Monad m) => SetEnv m where
+ setEnvS :: Env -> m ()
+instance Monad m => SetEnv (Lang m) where
+ setEnvS e = modify (\bnds -> bnds {bindingsEnv = e})
+
+class (Monad m) => GetSourceName m where
+ getSourceNameS :: m String
+class (Monad m) => HasPageWidth m where
+ getPageWidthS :: m PageWidth
+class (Monad m) => GetSubs m where
+ getSubsS :: m [(Text, Value -> m ())]
+class (Monad m) => SetSubs m where
+ setSubS :: Text -> (Value -> m ()) -> m ()
putStrLnS :: (Stdout m) => Text -> m ()
putStrLnS t = putStrS t >> putStrS "\n"
diff --git a/test/spec/Radicle/Internal/Arbitrary.hs b/test/spec/Radicle/Internal/Arbitrary.hs
index e7892a1..8001ff2 100644
--- a/test/spec/Radicle/Internal/Arbitrary.hs
+++ b/test/spec/Radicle/Internal/Arbitrary.hs
@@ -39,7 +39,7 @@ instance Arbitrary Value where
prims = purePrimops
instance Arbitrary Ident where
- arbitrary = ((:) <$> firstL <*> rest) `suchThatMap` (makeIdent . T.pack)
+ arbitrary = ((:) <$> firstL <*> rest) `suchThatMap` (mkIdent . T.pack)
where
allChars = take 100 ['!' .. maxBound]
firstL = elements $ filter isValidIdentFirst allChars
diff --git a/test/spec/Radicle/Internal/TestCapabilities.hs b/test/spec/Radicle/Internal/TestCapabilities.hs
index fd56048..19d587c 100644
--- a/test/spec/Radicle/Internal/TestCapabilities.hs
+++ b/test/spec/Radicle/Internal/TestCapabilities.hs
@@ -3,20 +3,18 @@
-- Radicle.Internal.Subscriber.Capabilities that may be used for testing.
module Radicle.Internal.TestCapabilities where
-import Control.Lens
-import Control.Monad.State
-import Data.Text (Text)
+import Control.Monad.State
+import Data.Text (Text)
-import Radicle
-import Radicle.Internal.Subscriber.Capabilities
+import Radicle
+import Radicle.Internal.Subscriber.Capabilities
data WorldState = WorldState
- { _worldStateStdin :: [Text]
- , _worldStateStdout :: [Text]
- , _worldStateEnv :: Env
+ { worldStateStdin :: [Text]
+ , worldStateStdout :: [Text]
+ , worldStateEnv :: Env
}
-makeFields ''WorldState
type TestLang = Lang (State WorldState)
@@ -28,12 +26,12 @@ runTestWith
-> (Either LangError a, [Text])
runTestWith bindings inputs action =
let ws = WorldState
- { _worldStateStdin = inputs
- , _worldStateStdout = []
- , _worldStateEnv = bindings ^. env
+ { worldStateStdin = inputs
+ , worldStateStdout = []
+ , worldStateEnv = bindingsEnv bindings
}
- in case runState (runLangT bindings action) ws of
- (val, st) -> (val, reverse $ st ^. stdout)
+ in case runState (runLang bindings action) ws of
+ (val, st) -> (val, reverse $ worldStateStdout st)
-- | Like `runTestWith`, but uses the pureEmptyEnv
runTestWith' :: [Text] -> TestLang a -> (Either LangError a, [Text])
@@ -41,7 +39,10 @@ runTestWith' = runTestWith pureEmptyEnv
instance Stdin (State WorldState) where
- getLineS = head <$> (stdin <<%= tail)
+ getLineS = do
+ ws <- get
+ put $ ws { worldStateStdin = tail $ worldStateStdin ws }
+ pure $ head $ worldStateStdin ws
instance Stdout (State WorldState) where
- putStrS t = stdout %= (t:)
+ putStrS t = modify (\ws -> ws { worldStateStdout = t:worldStateStdout ws })
diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hs
index 028dd66..97261d5 100644
--- a/test/spec/Radicle/Tests.hs
+++ b/test/spec/Radicle/Tests.hs
@@ -88,7 +88,8 @@ test_eval =
prog `failsWith` OtherError "define expects atom for first arg"
]
where
- run src = runLangM pureEmptyEnv $ interpretMany "(test)" src
+ run src = runIdentity $ runLang pureEmptyEnv
+ $ interpretMany "(test)" src
failsWith src err = run src @?= Left err
succeedsWith src val = run src @?= Right val
@@ -156,7 +157,7 @@ test_repl_primops =
]
where
run inp prog = fst $ runTestWith replBindings inp
- $ interpretMany "(test)" prog
+ $ interpretMany "(test)" prog
-- * Utils