A peer-to-peer stack for code collaboration
Add `instance {From/To}Rad ()`. (#135)
James Haydon5652db6d29cf
diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex 0facf11..7bb0463 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -21,6 +21,7 @@ import qualified Data.List.NonEmpty as NonEmptyimport qualified Data.Map as Mapimport Data.Scientific (Scientific, floatingOrInteger)import Data.Semigroup ((<>))+import Data.Sequence (Seq(..))import qualified Data.Sequence as Seqimport Generics.Eotimport qualified GHC.Exts as GhcExts@@ -484,6 +485,12 @@ class FromRad a wheredefault fromRad :: (HasEot a, FromRadG (Eot a)) => Value -> Either Text afromRad = fromRadG+instance FromRad () where+ fromRad (Vec Seq.Empty) = pure ()+ fromRad _ = Left "Expecting an empty vector"+instance (FromRad a, FromRad b) => FromRad (a,b) where+ fromRad (Vec (x :<| y :<| Seq.Empty)) = (,) <$> fromRad x <*> fromRad y+ fromRad _ = Left "Expecting a vector of length 2"instance FromRad Value wherefromRad = pureinstance FromRad Scientific where@@ -532,6 +539,10 @@ class ToRad a wheredefault toRad :: (HasEot a, ToRadG (Eot a)) => a -> ValuetoRad = toRadG+instance ToRad () where+ toRad _ = Vec Empty+instance (ToRad a, ToRad b) => ToRad (a,b) where+ toRad (x,y) = Vec $ toRad x :<| toRad y :<| Emptyinstance ToRad Int wheretoRad = Number . fromIntegralinstance ToRad Integer wherediff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hsindex f0ee195..38e01d6 100644--- a/test/spec/Radicle/Tests.hs+++ b/test/spec/Radicle/Tests.hs@@ -661,7 +661,11 @@ test_repl =test_from_to_radicle :: [TestTree]test_from_to_radicle =- [ testGroup "Env Value"+ [ testGroup "()"+ [ testForType (Proxy :: Proxy ()) ]+ , testGroup "(Foo, Foo)"+ [ testForType (Proxy :: Proxy (Foo, Foo)) ]+ , testGroup "Env Value"[ testForType (Proxy :: Proxy (Env Value)) ], testGroup "Bindings ()"[ testForType (Proxy :: Proxy (Bindings ())) ]