summaryrefslogtreecommitdiff
path: root/fig-utils/src/Fig/Prelude.hs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-01-16 21:32:53 -0500
committerLLLL Colonq <llll@colonq>2024-01-16 21:32:53 -0500
commitf7cd8abb5eda335c7c2beb66fd28d594e3f3b956 (patch)
treedcd2318acedf5640022a5db64f98b6e1ba3ffe24 /fig-utils/src/Fig/Prelude.hs
parent7a67a4ce8c207842d14414ed16587fe05cedafcc (diff)
Support JSON output
Diffstat (limited to 'fig-utils/src/Fig/Prelude.hs')
-rw-r--r--fig-utils/src/Fig/Prelude.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/fig-utils/src/Fig/Prelude.hs b/fig-utils/src/Fig/Prelude.hs
index 85a3ab3..80e5829 100644
--- a/fig-utils/src/Fig/Prelude.hs
+++ b/fig-utils/src/Fig/Prelude.hs
@@ -65,7 +65,7 @@ import Data.Void (Void)
import Data.Bool (Bool(..), otherwise, not, (&&), (||))
import Data.Char (Char, isUpper)
import Data.Int (Int)
-import Data.Text (Text, pack, unpack, unwords)
+import Data.Text (Text, pack, unpack, unwords, unlines)
import Data.Text.IO (hPutStrLn)
import Data.Text.Encoding (decodeUtf8, decodeUtf8', encodeUtf8)
import Data.ByteString (ByteString, readFile, writeFile)
@@ -95,6 +95,8 @@ import Control.Monad.State.Class (MonadState(..), get, put, modify)
import Control.Monad.Reader.Class (MonadReader(..), ask)
import Control.Exception.Safe (Exception, SomeException, IOException, MonadThrow, MonadCatch, MonadMask, throwM, try, catch, catchIO, bracket, bracketOnError)
+import qualified Data.Aeson as Aeson
+
tshow :: Show a => a -> Text
tshow = pack . show
@@ -123,6 +125,9 @@ class Pretty a where
instance Pretty Void where
pretty _ = ""
+instance Pretty a => Pretty [a] where
+ pretty xs = unlines $ pretty <$> xs
+
newtype Fix f = Fix { unFix :: f (Fix f) }
unFix :: Fix f -> f (Fix f)
unFix (Fix x) = x
@@ -130,3 +135,5 @@ instance Pretty (f (Fix f)) => Pretty (Fix f) where
pretty (Fix x) = pretty x
instance Show (f (Fix f)) => Show (Fix f) where
show (Fix x) = show x
+instance Aeson.ToJSON (f (Fix f)) => Aeson.ToJSON (Fix f) where
+ toJSON (Fix x) = Aeson.toJSON x