diff --git a/cardano-prelude-test/cardano-prelude-test.cabal b/cardano-prelude-test/cardano-prelude-test.cabal index dc3b1e59..ec7a1360 100644 --- a/cardano-prelude-test/cardano-prelude-test.cabal +++ b/cardano-prelude-test/cardano-prelude-test.cabal @@ -50,7 +50,6 @@ library , text , time default-language: Haskell2010 - default-extensions: NoImplicitPrelude ghc-options: -Wall if (!flag(development)) @@ -78,7 +77,6 @@ test-suite prelude-tests , hedgehog , text default-language: Haskell2010 - default-extensions: NoImplicitPrelude ghc-options: -threaded -rtsopts -Wall diff --git a/cardano-prelude-test/src/Test/Cardano/Prelude/Base16.hs b/cardano-prelude-test/src/Test/Cardano/Prelude/Base16.hs index 9cec2169..8da35c66 100644 --- a/cardano-prelude-test/src/Test/Cardano/Prelude/Base16.hs +++ b/cardano-prelude-test/src/Test/Cardano/Prelude/Base16.hs @@ -20,6 +20,7 @@ import qualified Data.Attoparsec.ByteString.Lazy as PLB import qualified Data.ByteString.Base16.Lazy as B16 import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy.Char8 as LB +import Prelude hiding ((.)) import Text.Printf (printf) -------------------------------------------------------------------------------- diff --git a/cardano-prelude-test/src/Test/Cardano/Prelude/Gen.hs b/cardano-prelude-test/src/Test/Cardano/Prelude/Gen.hs index 517bc372..43f7a517 100644 --- a/cardano-prelude-test/src/Test/Cardano/Prelude/Gen.hs +++ b/cardano-prelude-test/src/Test/Cardano/Prelude/Gen.hs @@ -18,6 +18,8 @@ import Hedgehog (Gen) import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range +import Prelude hiding ((.)) + genBytes :: Int -> Gen ByteString genBytes n = Gen.bytes (Range.singleton n) diff --git a/cardano-prelude-test/src/Test/Cardano/Prelude/Golden.hs b/cardano-prelude-test/src/Test/Cardano/Prelude/Golden.hs index 2b14f7aa..a48ec089 100644 --- a/cardano-prelude-test/src/Test/Cardano/Prelude/Golden.hs +++ b/cardano-prelude-test/src/Test/Cardano/Prelude/Golden.hs @@ -29,6 +29,7 @@ import qualified Data.Text as T import qualified Data.Text.Lazy as LT import Data.Text.Lazy.Builder (toLazyText) import Formatting.Buildable (build) +import Prelude hiding ((.)) import qualified Text.JSON.Canonical as Canonical import Hedgehog ( diff --git a/cardano-prelude-test/src/Test/Cardano/Prelude/Orphans.hs b/cardano-prelude-test/src/Test/Cardano/Prelude/Orphans.hs index 5c397e8a..2a1682b8 100644 --- a/cardano-prelude-test/src/Test/Cardano/Prelude/Orphans.hs +++ b/cardano-prelude-test/src/Test/Cardano/Prelude/Orphans.hs @@ -14,6 +14,8 @@ import Cardano.Prelude import qualified Crypto.Random as Rand +import Prelude hiding ((.)) + import Test.QuickCheck (Gen) import qualified Test.QuickCheck as QC diff --git a/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Arbitrary.hs b/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Arbitrary.hs index 6abb081a..f26dddd1 100644 --- a/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Arbitrary.hs +++ b/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Arbitrary.hs @@ -22,7 +22,9 @@ import Cardano.Prelude import Data.ByteString (pack) import qualified Data.ByteString.Lazy as BL (ByteString, pack) +import qualified Data.Text as Text import Formatting (build, sformat) +import Prelude hiding ((.)) import Test.QuickCheck (Arbitrary (..), Gen, listOf, scale, shuffle, vector) import Test.QuickCheck.Gen (unGen) import Test.QuickCheck.Instances.ByteString () @@ -57,10 +59,10 @@ instance Arbitrary a => Arbitrary (SmallGenerator a) where -- there's not enough elements. sublistN :: Int -> [a] -> Gen [a] sublistN n xs = do - let len = length xs + let len = Prelude.length xs if len < n then - panic $ + error . Text.unpack $ sformat ( "sublistN: requested " . build diff --git a/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Property.hs b/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Property.hs index 2e7fbe6e..f46224b6 100644 --- a/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Property.hs +++ b/cardano-prelude-test/src/Test/Cardano/Prelude/QuickCheck/Property.hs @@ -44,8 +44,9 @@ where import Cardano.Prelude -import Control.Monad (fail) import qualified Data.Semigroup as Semigroup +import qualified Data.Text as Text +import Prelude hiding ((.)) import qualified Test.Hspec as Hspec import Test.QuickCheck (Property, counterexample, property, (.&&.), (===)) @@ -63,15 +64,15 @@ qcIsJust Nothing = qcFail "expected Just, got Nothing" qcIsNothing :: Show a => Maybe a -> Property qcIsNothing Nothing = property True -qcIsNothing (Just x) = qcFail ("expected Nothing, got Just (" <> show x <> ")") +qcIsNothing (Just x) = qcFail ("expected Nothing, got Just (" <> Text.pack (show x) <> ")") qcIsLeft :: Show b => Either a b -> Property qcIsLeft (Left _) = property True -qcIsLeft (Right x) = qcFail ("expected Left, got Right (" <> show x <> ")") +qcIsLeft (Right x) = qcFail ("expected Left, got Right (" <> Text.pack (show x) <> ")") qcIsRight :: Show a => Either a b -> Property qcIsRight (Right _) = property True -qcIsRight (Left x) = qcFail ("expected Right, got Left (" <> show x <> ")") +qcIsRight (Left x) = qcFail ("expected Right, got Left (" <> Text.pack (show x) <> ")") qcElem :: (Show a, Eq a, Show (t a), Foldable t) => a -> t a -> Property qcElem x xs = @@ -87,7 +88,7 @@ qcNotElem x xs = -- | A property that is always false qcFail :: Text -> Property -qcFail s = counterexample (toS s) False +qcFail s = counterexample (Text.unpack s) False -------------------------------------------------------------------------------- -- Monadic testing @@ -104,7 +105,7 @@ assertProperty st text = unless st $ stopProperty text -- | Stop 'PropertyM' execution with given reason. The property will fail. stopProperty :: Monad m => Text -> PropertyM m a -stopProperty msg = stop failed {reason = toS msg} +stopProperty msg = stop failed {reason = Text.unpack msg} -- | Use 'stopProperty' if the value is 'Nothing' or return something -- it the value is 'Just'. @@ -116,7 +117,7 @@ maybeStopProperty msg = \case -- | Split given list into chunks with size up to given value. -- TODO: consider using `sumEquals maxSize (length items)` splitIntoChunks :: Monad m => Word -> [a] -> PropertyM m [NonEmpty a] -splitIntoChunks 0 _ = panic "splitIntoChunks: maxSize is 0" +splitIntoChunks 0 _ = error "splitIntoChunks: maxSize is 0" splitIntoChunks maxSize items = do sizeMinus1 <- pick $ choose (0, maxSize - 1) let (chunk, rest) = splitAt (fromIntegral sizeMinus1 + 1) items @@ -141,7 +142,7 @@ expectedOne desc = \case splitWord :: Word64 -> Word64 -> Gen [Word64] splitWord total parts | total < parts = - panic $ + error $ "splitWord: can't split " <> show total <> " into " @@ -166,7 +167,7 @@ sumEquals maxEl restSum = do (el :) <$> sumEquals maxEl (restSum - el) expectationError :: Text -> Hspec.Expectation -expectationError = fail . toS +expectationError = fail . Text.unpack -------------------------------------------------------------------------------- -- Monoid/Semigroup laws diff --git a/cardano-prelude-test/src/Test/Cardano/Prelude/Tripping.hs b/cardano-prelude-test/src/Test/Cardano/Prelude/Tripping.hs index 325b17e5..20a8d6e5 100644 --- a/cardano-prelude-test/src/Test/Cardano/Prelude/Tripping.hs +++ b/cardano-prelude-test/src/Test/Cardano/Prelude/Tripping.hs @@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} @@ -20,10 +21,12 @@ where import Cardano.Prelude import Data.Aeson (FromJSON, ToJSON, decode, encode, fromJSON, toJSON) -import qualified Data.Map as Map -import Data.String (String, unlines) +import Data.Map qualified as Map +import Data.String (unlines) import Data.Text.Internal.Builder (toLazyText) +import Data.Text.Lazy qualified as LazyText import Formatting.Buildable (Buildable (..)) +import Prelude hiding ((.)) import System.IO (hSetEncoding, utf8) import qualified Text.JSON.Canonical as CanonicalJSON import Text.Show.Pretty (Value (..), parseValue) @@ -182,4 +185,4 @@ instance (Buildable e, Buildable a) => Buildable (Either e a) where build (Right a) = build a buildValue :: Buildable a => a -> Maybe Value -buildValue = parseValue . toS . toLazyText . build +buildValue = parseValue . LazyText.unpack . toLazyText . build diff --git a/cardano-prelude-test/test/Test/Cardano/Prelude/GHC/Heap/TreeSpec.hs b/cardano-prelude-test/test/Test/Cardano/Prelude/GHC/Heap/TreeSpec.hs index 186adf72..82ac19d5 100644 --- a/cardano-prelude-test/test/Test/Cardano/Prelude/GHC/Heap/TreeSpec.hs +++ b/cardano-prelude-test/test/Test/Cardano/Prelude/GHC/Heap/TreeSpec.hs @@ -49,7 +49,7 @@ prop_Word8ListClosureTreeDepth = failure Just ct -> do annotate $ unpack (renderTree ct renderClosure) - depth ct === (length xs) + 1 + depth ct === (Cardano.Prelude.length xs) + 1 -- | Property: Specifying a 'TreeDepth' other than 'AnyDepth' should -- appropriately limit the maximum depth of the 'Closure' 'Tree' generated. @@ -74,7 +74,7 @@ prop_ClosureTreeHasSpecifiedDepth = withTests 500 $ property $ do Just ct -> do annotate $ unpack (renderTree ct renderClosure) if depth ct < maxDepth - then depth ct === length xs + 1 + then depth ct === Cardano.Prelude.length xs + 1 else depth ct === maxDepth tests :: IO Bool diff --git a/cardano-prelude-test/test/test.hs b/cardano-prelude-test/test/test.hs index 3fd70790..770f1463 100644 --- a/cardano-prelude-test/test/test.hs +++ b/cardano-prelude-test/test/test.hs @@ -2,7 +2,6 @@ module Main ( main, ) where -import Cardano.Prelude import Test.Cardano.Prelude import qualified Test.Cardano.Prelude.GHC.Heap.NormalFormSpec diff --git a/cardano-prelude/cardano-prelude.cabal b/cardano-prelude/cardano-prelude.cabal index c2b2ecef..31a482ac 100644 --- a/cardano-prelude/cardano-prelude.cabal +++ b/cardano-prelude/cardano-prelude.cabal @@ -26,7 +26,6 @@ library exposed-modules: Cardano.Prelude Data.Semigroup.Action other-modules: Cardano.Prelude.Base - Cardano.Prelude.Compat Cardano.Prelude.Compat.ByteString.Short Cardano.Prelude.Error Cardano.Prelude.Formatting @@ -47,18 +46,17 @@ library , canonical-json >= 0.6.0.1 , cborg , containers + , deepseq , formatting , ghc-heap , ghc-prim , integer-gmp , microlens , mtl - , protolude , tagged , text , time default-language: Haskell2010 - default-extensions: NoImplicitPrelude c-sources: cbits/hashset.c cbits/worklist.c cbits/closure_size.c diff --git a/cardano-prelude/src/Cardano/Prelude.hs b/cardano-prelude/src/Cardano/Prelude.hs index 1fc235a5..ffe824da 100644 --- a/cardano-prelude/src/Cardano/Prelude.hs +++ b/cardano-prelude/src/Cardano/Prelude.hs @@ -3,8 +3,7 @@ module Cardano.Prelude ( ) where -import Cardano.Prelude.Base as X hiding (readEither) -import Cardano.Prelude.Compat as X (readEither) +import Cardano.Prelude.Base as X import Cardano.Prelude.Compat.ByteString.Short as X import Cardano.Prelude.Error as X import Cardano.Prelude.Formatting as X diff --git a/cardano-prelude/src/Cardano/Prelude/Base.hs b/cardano-prelude/src/Cardano/Prelude/Base.hs index d61a0808..b5716c5b 100644 --- a/cardano-prelude/src/Cardano/Prelude/Base.hs +++ b/cardano-prelude/src/Cardano/Prelude/Base.hs @@ -1,61 +1,78 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE ExplicitNamespaces #-} {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE ImportQualifiedPost #-} +{-# LANGUAGE RankNTypes #-} {-# LANGUAGE Safe #-} module Cardano.Prelude.Base ( module X, + HasLength (..), identity, putTextLn, - length, + scanl', + Cardano.Prelude.Base.length, #if __GLASGOW_HASKELL__ >= 906 type (~) #endif ) where -import Protolude as X hiding ( - Hashable, - Map, - hash, - hashUsing, - hashWithSalt, - identity, - length, - witness, - (.), - ) -import qualified Protolude as Y - import Data.Map.Strict as X (Map) -import qualified Data.Text as T +import Data.List (scanl') +import Data.Text as X (Text) +import Data.Text qualified as Text +import Data.Text.IO qualified as Text -import Control.Category (id) +import Control.Category qualified as Category import Control.Category as X hiding (id) import Numeric.Natural as X -#if __GLASGOW_HASKELL__ >= 906 -import Prelude (type (~)) -#endif +import Control.Applicative as X (many) +import Control.Concurrent.MVar as X (MVar, newMVar) +import Control.DeepSeq as X (NFData (..), ($!!), force) +import Control.Exception as X (Exception, bracket) +import Control.Monad as X (liftM, unless) +import Control.Monad.Except as X (MonadError, throwError) +import Control.Monad.IO.Class as X (MonadIO (..)) +import Data.ByteString as X (ByteString) +import Data.Bifunctor as X (first) +import Data.Functor.Identity as X (Identity, runIdentity) +import Data.Int as X (Int8, Int16, Int32, Int64) +import Data.Ord as X (Ord (..), comparing) +import Data.List as X (sortBy) +import Data.List.NonEmpty as X (NonEmpty (..), nonEmpty) +import Data.Maybe as X (catMaybes) +import Data.Proxy as X (Proxy (..)) +import Data.Ratio as X ((%), denominator, numerator) +import Data.Semigroup as X (Semigroup (..), Any, diff) +import Data.Typeable as X (Typeable, typeRep) +import Data.Word as X (Word8, Word16, Word32, Word64) +import Foreign.Ptr as X (Ptr) +import GHC.Generics as X (Generic) +import GHC.Stack as X +import System.Exit as X +import System.IO as X (Handle, stderr, stdout) +import Text.Read as X (readEither) -- | Rename `id` to `identity` to allow `id` as a variable name identity :: Category cat => cat a a -identity = id +identity = Category.id -- | Explicit output with @Text@ since that is what we want most of the time. -- We don't want to look at the type errors or warnings arising. putTextLn :: Text -> IO () -putTextLn = putStrLn +putTextLn = Text.putStrLn -- Length which includes @Text@ as well as @Foldable@. class HasLength a where length' :: a -> Int instance HasLength Text where - length' = T.length + length' = Text.length instance Foldable t => HasLength (t a) where - length' = Y.length + length' = Prelude.length -- | We can pass several things here, as long as they have length. length :: HasLength a => a -> Int diff --git a/cardano-prelude/src/Cardano/Prelude/Compat.hs b/cardano-prelude/src/Cardano/Prelude/Compat.hs deleted file mode 100644 index be163560..00000000 --- a/cardano-prelude/src/Cardano/Prelude/Compat.hs +++ /dev/null @@ -1,18 +0,0 @@ -{-# LANGUAGE FlexibleContexts #-} - -module Cardano.Prelude.Compat ( - readEither, -) where - -import Data.Bifunctor (Bifunctor (first)) -import Data.Either (Either) -import Data.Function ((.)) -import Data.String (String) -import Text.Read (Read) - -import qualified Protolude.Conv as Conv -import qualified Text.Read as Read - --- TODO Delete this when all projects have updated protolude-0.3.2 -readEither :: (Read a, Conv.StringConv String e, Conv.StringConv e String) => e -> Either e a -readEither = first Conv.toS . Read.readEither . Conv.toS diff --git a/cardano-prelude/src/Cardano/Prelude/Compat/ByteString/Short.hs b/cardano-prelude/src/Cardano/Prelude/Compat/ByteString/Short.hs index e5e45de6..67fecfa9 100644 --- a/cardano-prelude/src/Cardano/Prelude/Compat/ByteString/Short.hs +++ b/cardano-prelude/src/Cardano/Prelude/Compat/ByteString/Short.hs @@ -5,14 +5,14 @@ module Cardano.Prelude.Compat.ByteString.Short ( unsafeShortByteStringIndex, ) where +import Cardano.Prelude.Base + -- GHC >= 9.0 does not export unsafeIndex for ShortByteString -- GHC < 9.0 does not export the ShortByteString constructor SBS. -- Coniditional compile to work around this. #if __GLASGW_HASKELL__ >= 900 import Data.ByteString.Short (ShortByteString(..)) -import Data.Int (Int) -import Data.Word (Word8) import GHC.Exts (indexWord8Array#) unsafeShortByteStringIndex :: ShortByteString -> Int -> Word8 @@ -21,8 +21,6 @@ unsafeShortByteStringIndex (SBS ba#) (I# i#) = W8# (indexWord8Array# ba# i#) #else import Data.ByteString.Short (ShortByteString, index) -import Data.Int (Int) -import Data.Word (Word8) unsafeShortByteStringIndex :: ShortByteString -> Int -> Word8 unsafeShortByteStringIndex = index diff --git a/cardano-prelude/src/Cardano/Prelude/Error.hs b/cardano-prelude/src/Cardano/Prelude/Error.hs index 8614ecf2..7349232a 100644 --- a/cardano-prelude/src/Cardano/Prelude/Error.hs +++ b/cardano-prelude/src/Cardano/Prelude/Error.hs @@ -12,11 +12,11 @@ where import Cardano.Prelude.Base import qualified Codec.CBOR.Decoding as CBOR -import Control.Monad (fail) import Control.Monad.Except (liftEither) import qualified Data.Aeson.Types as A import Formatting (build, formatToString) import Formatting.Buildable (Buildable) +import Prelude hiding ((.)) -- | Convert an 'Either'-encoded error to an 'aeson' parser error toAesonError :: Buildable e => Either e a -> A.Parser a diff --git a/cardano-prelude/src/Cardano/Prelude/Formatting.hs b/cardano-prelude/src/Cardano/Prelude/Formatting.hs index 4bf97433..0af58259 100644 --- a/cardano-prelude/src/Cardano/Prelude/Formatting.hs +++ b/cardano-prelude/src/Cardano/Prelude/Formatting.hs @@ -44,6 +44,7 @@ import Formatting (Format, bprint, later) import qualified Formatting as F (build) import Formatting.Buildable (Buildable (build)) import qualified GHC.Exts as Exts +import Prelude hiding ((.)) -------------------------------------------------------------------------------- -- Base16 diff --git a/cardano-prelude/src/Cardano/Prelude/GHC/Heap/NormalForm.hs b/cardano-prelude/src/Cardano/Prelude/GHC/Heap/NormalForm.hs index 90be39e0..28cd64a2 100644 --- a/cardano-prelude/src/Cardano/Prelude/GHC/Heap/NormalForm.hs +++ b/cardano-prelude/src/Cardano/Prelude/GHC/Heap/NormalForm.hs @@ -52,8 +52,6 @@ module Cardano.Prelude.GHC.Heap.NormalForm ( ) where -import Cardano.Prelude.Base - import GHC.Exts.Heap -- Everything is in normal form, unless it is a diff --git a/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Size.hs b/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Size.hs index 53ea129f..eb2b90dc 100644 --- a/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Size.hs +++ b/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Size.hs @@ -49,7 +49,7 @@ toCountFailure n | n == cVISITED_FULL = Just $ VisitedFull | n == cOUT_OF_MEMORY = Just $ OutOfMemory | n >= cUNSUPPORTED_CLOSURE = Just $ UnsupportedClosure typ - | otherwise = panic "getCountFailure: impossible" + | otherwise = error "getCountFailure: impossible" where typ :: ClosureType typ = toEnum (fromIntegral (n - cUNSUPPORTED_CLOSURE)) diff --git a/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Tree.hs b/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Tree.hs index 2e319ccf..d86906a5 100644 --- a/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Tree.hs +++ b/cardano-prelude/src/Cardano/Prelude/GHC/Heap/Tree.hs @@ -23,7 +23,7 @@ where import Cardano.Prelude.Base -import Data.Text (pack, unpack) +import qualified Data.Text as Text import Data.Tree (Tree (..), drawTree, levels) import GHC.Exts.Heap ( Box (..), @@ -33,6 +33,7 @@ import GHC.Exts.Heap ( asBox, getClosureData, ) +import Prelude hiding ((.)) import System.Mem (performGC) -- | The depth of a 'Tree'. @@ -61,7 +62,7 @@ data ClosureTreeOptions = ClosureTreeOptions deriving (Show) depth :: Tree a -> Int -depth = length . levels +depth = Cardano.Prelude.Base.length . levels isZeroOrNegativeTreeDepth :: TreeDepth -> Bool isZeroOrNegativeTreeDepth AnyDepth = False @@ -70,10 +71,10 @@ isZeroOrNegativeTreeDepth (TreeDepth d) | otherwise = False renderClosure :: Closure -> Text -renderClosure = show +renderClosure = Text.pack . show renderTree :: Tree a -> (a -> Text) -> Text -renderTree tree renderA = pack $ drawTree (fmap (unpack . renderA) tree) +renderTree tree renderA = Text.pack $ drawTree (fmap (Text.unpack . renderA) tree) -- | Given a Haskell expression, build a 'Tree' which reflects its heap object -- representation. diff --git a/cardano-prelude/src/Cardano/Prelude/Json/Canonical.hs b/cardano-prelude/src/Cardano/Prelude/Json/Canonical.hs index d5017ac4..efe86aa5 100644 --- a/cardano-prelude/src/Cardano/Prelude/Json/Canonical.hs +++ b/cardano-prelude/src/Cardano/Prelude/Json/Canonical.hs @@ -20,6 +20,8 @@ where import Cardano.Prelude.Base import Cardano.Prelude.Json.Parse (parseJSString) import Data.Fixed (E12, resolution) +import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text import Data.Time (NominalDiffTime, UTCTime) import Data.Time.Clock.POSIX ( posixSecondsToUTCTime, @@ -35,9 +37,9 @@ import Text.JSON.Canonical ( ToJSON (toJSON), ) -import qualified Cardano.Prelude.Compat as I import qualified Data.ByteString.Lazy as LB import qualified Data.Text.Lazy.Builder as Builder +import Prelude hiding ((.)) import qualified Text.JSON.Canonical as CanonicalJSON data SchemaError = SchemaError @@ -62,8 +64,8 @@ instance expected expec actual = throwError SchemaError - { seExpected = toS expec - , seActual = fmap toS actual + { seExpected = Text.pack expec + , seActual = fmap Text.pack actual } instance Monad m => ToJSON m Int32 where @@ -109,13 +111,13 @@ instance ReportSchemaErrors m => FromJSON m Word32 where fromJSON val = CanonicalJSON.expectedButGotValue "Word32" val instance ReportSchemaErrors m => FromJSON m Word64 where - fromJSON = parseJSString (I.readEither @Word64 @Text . toS) + fromJSON = parseJSString (readEither . Text.unpack) instance ReportSchemaErrors m => FromJSON m Integer where - fromJSON = parseJSString (I.readEither @Integer @Text . toS) + fromJSON = parseJSString (readEither . Text.unpack) instance MonadError SchemaError m => FromJSON m Natural where - fromJSON = parseJSString (I.readEither @Natural @Text . toS) + fromJSON = parseJSString (readEither . Text.unpack) instance MonadError SchemaError m => FromJSON m UTCTime where fromJSON = fmap (posixSecondsToUTCTime . fromIntegral) . fromJSON @_ @Int54 @@ -129,15 +131,15 @@ canonicalDecodePretty :: LB.ByteString -> Either Text a canonicalDecodePretty y = do - eVal <- first toS (CanonicalJSON.parseCanonicalJSON y) - first show (CanonicalJSON.fromJSON eVal :: Either SchemaError a) + eVal <- first Text.pack (CanonicalJSON.parseCanonicalJSON y) + first (Text.pack . show) (CanonicalJSON.fromJSON eVal :: Either SchemaError a) canonicalEncodePretty :: forall a. CanonicalJSON.ToJSON Identity a => a -> LB.ByteString canonicalEncodePretty x = LB.fromStrict - . encodeUtf8 - . toS + . Text.encodeUtf8 + . Text.pack $ CanonicalJSON.prettyCanonicalJSON $ runIdentity $ CanonicalJSON.toJSON x diff --git a/cardano-prelude/src/Cardano/Prelude/Json/Parse.hs b/cardano-prelude/src/Cardano/Prelude/Json/Parse.hs index ec0396ce..2454ed63 100644 --- a/cardano-prelude/src/Cardano/Prelude/Json/Parse.hs +++ b/cardano-prelude/src/Cardano/Prelude/Json/Parse.hs @@ -11,9 +11,10 @@ where import Cardano.Prelude.Base -import Data.String (String) +import qualified Data.Text as Text import Formatting (Format, build, formatToString, string) import Formatting.Buildable (Buildable) +import Prelude hiding ((.)) import Text.JSON.Canonical ( JSValue (JSString), ReportSchemaErrors (expected), @@ -31,7 +32,7 @@ parseJSString :: m a parseJSString parser = \case JSString str -> - either (report $ fromJSString str) pure . parser . toS $ fromJSString str + either (report $ fromJSString str) pure . parser . Text.pack $ fromJSString str val -> expectedButGotValue typeName val where typeName :: String diff --git a/cardano-prelude/src/Cardano/Prelude/Microlens.hs b/cardano-prelude/src/Cardano/Prelude/Microlens.hs index 28026189..b9f6d631 100644 --- a/cardano-prelude/src/Cardano/Prelude/Microlens.hs +++ b/cardano-prelude/src/Cardano/Prelude/Microlens.hs @@ -4,7 +4,6 @@ module Cardano.Prelude.Microlens () where -import Data.Functor ((<$>)) import Lens.Micro.Internal (Field1 (..), Field2 (..), Field3 (..), Field4 (..), Field5 (..)) instance Field1 (a, b, c, d, e, f) (a', b, c, d, e, f) a a' where diff --git a/cardano-prelude/src/Cardano/Prelude/Strict.hs b/cardano-prelude/src/Cardano/Prelude/Strict.hs index 6e50d774..9108cdfb 100644 --- a/cardano-prelude/src/Cardano/Prelude/Strict.hs +++ b/cardano-prelude/src/Cardano/Prelude/Strict.hs @@ -4,8 +4,6 @@ module Cardano.Prelude.Strict ( ) where -import Cardano.Prelude.Base - -- | Force all of the elements of a 'Foldable' to weak head normal form. -- -- In order to ensure that all of the elements of a 'Foldable' are strict, we diff --git a/cardano-prelude/src/Data/Semigroup/Action.hs b/cardano-prelude/src/Data/Semigroup/Action.hs index e74f3e72..df1d1269 100644 --- a/cardano-prelude/src/Data/Semigroup/Action.hs +++ b/cardano-prelude/src/Data/Semigroup/Action.hs @@ -6,8 +6,6 @@ module Data.Semigroup.Action ( ) where -import Data.Semigroup (Semigroup, (<>)) - -- | Semigroup action. It should satisfy: -- -- @