| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusPrelude
Contents
- Reexports from base
- Lens
- Debugging
- Reexports from Text
- class Default a where
- def :: a
- zipExact :: [a] -> [b] -> Maybe [(a, b)]
- allSame :: Eq a => [a] -> Bool
- distinct :: Eq a => [a] -> Bool
- unsafeFromRight :: Show e => Either e a -> a
- addTheRest :: [a] -> [(a, [a])]
- lowerInitialChar :: String -> String
Reexports from base
(&&&) :: Arrow a => a b c -> a b c' -> a b (c, c') infixr 3 #
Fanout: send the input to both argument arrows and combine their output.
The default definition may be overridden with a more efficient version if desired.
(>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c infixr 1 #
Left-to-right composition
toList :: Foldable t => t a -> [a] #
List of elements of a structure, from left to right. If the entire list is intended to be reduced via a fold, just fold the structure directly bypassing the list.
Examples
Basic usage:
>>>toList Nothing[]
>>>toList (Just 42)[42]
>>>toList (Left "foo")[]
>>>toList (Node (Leaf 5) 17 (Node Empty 12 (Leaf 8)))[5,17,12,8]
For lists, toList is the identity:
>>>toList [1, 2, 3][1,2,3]
Since: base-4.8.0.0
fromMaybe :: a -> Maybe a -> a #
The fromMaybe function takes a default value and a Maybe
value. If the Maybe is Nothing, it returns the default value;
otherwise, it returns the value contained in the Maybe.
Examples
Basic usage:
>>>fromMaybe "" (Just "Hello, World!")"Hello, World!"
>>>fromMaybe "" Nothing""
Read an integer from a string using readMaybe. If we fail to
parse an integer, we want to return 0 by default:
>>>import Text.Read ( readMaybe )>>>fromMaybe 0 (readMaybe "5")5>>>fromMaybe 0 (readMaybe "")0
guard :: Alternative f => Bool -> f () #
Conditional failure of Alternative computations. Defined by
guard True =pure() guard False =empty
Examples
Common uses of guard include conditionally signaling an error in
an error monad and conditionally rejecting the current choice in an
Alternative-based parser.
As an example of signaling an error in the error monad Maybe,
consider a safe division function safeDiv x y that returns
Nothing when the denominator y is zero and otherwise. For example:Just (x `div`
y)
>>>safeDiv 4 0Nothing
>>>safeDiv 4 2Just 2
A definition of safeDiv using guards, but not guard:
safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0 = Just (x `div` y)
| otherwise = Nothing
A definition of safeDiv using guard and Monad do-notation:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b #
Left-associative fold of a structure but with strict application of the operator.
This ensures that each step of the fold is forced to Weak Head Normal
Form before being applied, avoiding the collection of thunks that would
otherwise occur. This is often what you want to strictly reduce a
finite structure to a single strict result (e.g. sum).
For a general Foldable structure this should be semantically identical
to,
foldl' f z =foldl'f z .toList
Since: base-4.6.0.0
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () #
for_ is traverse_ with its arguments flipped. For a version
that doesn't ignore the results see for. This
is forM_ generalised to Applicative actions.
for_ is just like forM_, but generalised to Applicative actions.
Examples
Basic usage:
>>>for_ [1..4] print1 2 3 4
traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () #
Map each element of a structure to an Applicative action, evaluate these
actions from left to right, and ignore the results. For a version that
doesn't ignore the results see traverse.
traverse_ is just like mapM_, but generalised to Applicative actions.
Examples
Basic usage:
>>>traverse_ print ["Hello", "world", "!"]"Hello" "world" "!"
fold :: (Foldable t, Monoid m) => t m -> m #
Given a structure with elements whose type is a Monoid, combine them
via the monoid's ( operator. This fold is right-associative and
lazy in the accumulator. When you need a strict left-associative fold,
use <>)foldMap' instead, with id as the map.
Examples
Basic usage:
>>>fold [[1, 2, 3], [4, 5], [6], []][1,2,3,4,5,6]
>>>fold $ Node (Leaf (Sum 1)) (Sum 3) (Leaf (Sum 5))Sum {getSum = 9}
Folds of unbounded structures do not terminate when the monoid's
( operator is strict:<>)
>>>fold (repeat Nothing)* Hangs forever *
Lazy corecursive folds of unbounded structures are fine:
>>>take 12 $ fold $ map (\i -> [i..i+2]) [0..][0,1,2,1,2,3,2,3,4,3,4,5]>>>sum $ take 4000000 $ fold $ map (\i -> [i..i+2]) [0..]2666668666666
for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) #
throw :: forall (r :: RuntimeRep) (a :: TYPE r) e. Exception e => e -> a #
Throw an exception. Exceptions may be thrown from purely
functional code, but may only be caught within the IO monad.
WARNING: You may want to use throwIO instead so that your pure code
stays exception-free.
join :: Monad m => m (m a) -> m a #
The join function is the conventional monad join operator. It
is used to remove one level of monadic structure, projecting its
bound argument into the outer level.
'' can be understood as the join bssdo expression
do bs <- bss bs
Examples
A common use of join is to run an IO computation returned from
an STM transaction, since STM transactions
can't perform IO directly. Recall that
atomically :: STM a -> IO a
is used to run STM transactions atomically. So, by
specializing the types of atomically and join to
atomically:: STM (IO b) -> IO (IO b)join:: IO (IO b) -> IO b
we can compose them as
join.atomically:: STM (IO b) -> IO b
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right composition of Kleisli arrows.
'(bs ' can be understood as the >=> cs) ado expression
do b <- bs a cs b
($>) :: Functor f => f a -> b -> f b infixl 4 #
Flipped version of <$.
Examples
Replace the contents of a with a constant
Maybe IntString:
>>>Nothing $> "foo"Nothing>>>Just 90210 $> "foo"Just "foo"
Replace the contents of an
with a constant Either Int IntString, resulting in an :Either
Int String
>>>Left 8675309 $> "foo"Left 8675309>>>Right 8675309 $> "foo"Right "foo"
Replace each element of a list with a constant String:
>>>[1,2,3] $> "foo"["foo","foo","foo"]
Replace the second element of a pair with a constant String:
>>>(1,2) $> "foo"(1,"foo")
Since: base-4.7.0.0
fromRight :: b -> Either a b -> b #
Return the contents of a Right-value or a default value otherwise.
Examples
Basic usage:
>>>fromRight 1 (Right 3)3>>>fromRight 1 (Left "foo")1
Since: base-4.10.0.0
isRight :: Either a b -> Bool #
Return True if the given value is a Right-value, False otherwise.
Examples
Basic usage:
>>>isRight (Left "foo")False>>>isRight (Right 3)True
Assuming a Left value signifies some sort of error, we can use
isRight to write a very simple reporting function that only
outputs "SUCCESS" when a computation has succeeded.
This example shows how isRight might be used to avoid pattern
matching when one does not care about the value contained in the
constructor:
>>>import Control.Monad ( when )>>>let report e = when (isRight e) $ putStrLn "SUCCESS">>>report (Left "parse error")>>>report (Right 1)SUCCESS
Since: base-4.7.0.0
isLeft :: Either a b -> Bool #
Return True if the given value is a Left-value, False otherwise.
Examples
Basic usage:
>>>isLeft (Left "foo")True>>>isLeft (Right 3)False
Assuming a Left value signifies some sort of error, we can use
isLeft to write a very simple error-reporting function that does
absolutely nothing in the case of success, and outputs "ERROR" if
any error occurred.
This example shows how isLeft might be used to avoid pattern
matching when one does not care about the value contained in the
constructor:
>>>import Control.Monad ( when )>>>let report e = when (isLeft e) $ putStrLn "ERROR">>>report (Right 1)>>>report (Left "parse error")ERROR
Since: base-4.7.0.0
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing>>>void (Just 3)Just ()
Replace the contents of an
with unit, resulting in an Either Int Int:Either Int ()
>>>void (Left 8675309)Left 8675309>>>void (Right 8675309)Right ()
Replace every element of a list with unit:
>>>void [1,2,3][(),(),()]
Replace the second element of a pair with unit:
>>>void (1,2)(1,())
Discard the result of an IO action:
>>>mapM print [1,2]1 2 [(),()]>>>void $ mapM print [1,2]1 2
through :: Functor f => (a -> f b) -> a -> f a #
Makes an effectful function ignore its result value and return its input value.
coerce :: forall {k :: RuntimeRep} (a :: TYPE k) (b :: TYPE k). Coercible a b => a -> b #
The function coerce allows you to safely convert between values of
types that have the same representation with no run-time overhead. In the
simplest case you can use it instead of a newtype constructor, to go from
the newtype's concrete type to the abstract type. But it also works in
more complicated settings, e.g. converting a list of newtypes to a list of
concrete types.
When used in conversions involving a newtype wrapper, make sure the newtype constructor is in scope.
This function is representation-polymorphic, but the
RuntimeRep type argument is marked as Inferred, meaning
that it is not available for visible type application. This means
the typechecker will accept .coerce @Int @Age 42
Examples
>>>newtype TTL = TTL Int deriving (Eq, Ord, Show)>>>newtype Age = Age Int deriving (Eq, Ord, Show)>>>coerce (Age 42) :: TTLTTL 42>>>coerce (+ (1 :: Int)) (Age 42) :: TTLTTL 43>>>coerce (map (+ (1 :: Int))) [Age 42, Age 24] :: [TTL][TTL 43,TTL 25]
coerceVia :: Coercible a b => (a -> b) -> a -> b #
Coerce the second argument to the result type of the first one. The motivation for this
function is that it's often more annoying to explicitly specify a target type for coerce than
to construct an explicit coercion function, so this combinator can be used in cases like that.
Plus the code reads better, as it becomes clear what and where gets wrapped/unwrapped.
coerceArg :: Coercible a b => (a -> s) -> b -> s #
Same as f -> f . coerce, but does not create any closures and so is completely free.
coerceRes :: Coercible s t => (a -> s) -> a -> t #
Same as f -> coerce . f, but does not create any closures and so is completely free.
(#.) :: Coercible b c => (b -> c) -> (a -> b) -> a -> c #
Same as (.), but ignores the first argument and uses a no-op coerction instead.
Representable types of kind *.
This class is derivable in GHC with the DeriveGeneric flag on.
A Generic instance must satisfy the following laws:
from.to≡idto.from≡id
Defined in Control.DeepSeq
This instance is for convenience and consistency with seq.
This assumes that WHNF is equivalent to NF for functions.
Since: deepseq-1.3.0.0
Defined in Data.Aeson.Types.ToJSON
Methods
toEncoding :: Natural -> Encoding
toJSONList :: [Natural] -> Value
toEncodingList :: [Natural] -> Encoding
Defined in Data.Aeson.Types.ToJSON
Since: base-4.8.0.0
Defined in Data.Data
Methods
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Natural -> c Natural #
gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Natural #
toConstr :: Natural -> Constr #
dataTypeOf :: Natural -> DataType #
dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Natural) #
dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Natural) #
gmapT :: (forall b. Data b => b -> b) -> Natural -> Natural #
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r #
gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r #
gmapQ :: (forall d. Data d => d -> u) -> Natural -> [u] #
gmapQi :: Int -> (forall d. Data d => d -> u) -> Natural -> u #
gmapM :: Monad m => (forall d. Data d => d -> m d) -> Natural -> m Natural #
gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural #
gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural #
Since: base-4.8.0
Defined in GHC.Bits
Methods
(.&.) :: Natural -> Natural -> Natural #
(.|.) :: Natural -> Natural -> Natural #
xor :: Natural -> Natural -> Natural #
complement :: Natural -> Natural #
shift :: Natural -> Int -> Natural #
rotate :: Natural -> Int -> Natural #
setBit :: Natural -> Int -> Natural #
clearBit :: Natural -> Int -> Natural #
complementBit :: Natural -> Int -> Natural #
testBit :: Natural -> Int -> Bool #
bitSizeMaybe :: Natural -> Maybe Int #
shiftL :: Natural -> Int -> Natural #
unsafeShiftL :: Natural -> Int -> Natural #
shiftR :: Natural -> Int -> Natural #
unsafeShiftR :: Natural -> Int -> Natural #
rotateL :: Natural -> Int -> Natural #
Since: base-4.8.0.0
Since: base-4.8.0.0
Defined in GHC.Ix
Note that Natural's Num instance isn't a ring: no element but 0 has an
additive inverse. It is a semiring though.
Since: base-4.8.0.0
Defined in Text.PrettyBy.Internal
Methods
defaultPrettyBy :: config -> Natural -> Doc ann #
defaultPrettyListBy :: config -> [Natural] -> Doc ann #
>>>prettyBy () (123 :: Natural)123
Defined in Text.PrettyBy.Internal
Methods
defaultPrettyBy :: config -> NonEmpty a -> Doc ann #
defaultPrettyListBy :: config -> [NonEmpty a] -> Doc ann #
prettyBy for NonEmpty a is defined in terms of prettyListBy by default.
>>>prettyBy () (True :| [False])[True, False]>>>prettyBy () ('a' :| "bc")abc>>>prettyBy () (Just False :| [Nothing, Just True])[False, True]
Defined in PlutusCore.Flat.Data.ByteString.Convert
Methods
toByteString :: [Word8] -> MVector s Word64)
Defined in PlutusCore.Default.Universe
Defined in PlutusCore.Default.Universe
Defined in PlutusCore.Default.Universe
class Applicative f => Alternative (f :: Type -> Type) where #
A monoid on applicative functors.
If defined, some and many should be the least solutions
of the equations:
Takes the first non-throwing IO action's result.
empty throws an exception.
Since: base-4.9.0.0
Since: base-4.9.0.0
Since: base-4.9.0.0
Since: base-4.9.0.0
Defined in PlutusCore.Normalize.Internal
Methods
empty :: NormalizeTypeT m tyname uni ann a #
(<|>) :: NormalizeTypeT m tyname uni ann a -> NormalizeTypeT m tyname uni ann a -> NormalizeTypeT m tyname uni ann a #
some :: NormalizeTypeT m tyname uni ann a -> NormalizeTypeT m tyname uni ann [a] #
many :: NormalizeTypeT m tyname uni ann a -> NormalizeTypeT m tyname uni ann [a] #
class (Typeable e, Show e) => Exception e #
Any type that you wish to throw or catch as an exception must be an
instance of the Exception class. The simplest case is a new exception
type directly below the root:
data MyException = ThisException | ThatException
deriving Show
instance Exception MyExceptionThe default method definitions in the Exception class do what we need
in this case. You can now throw and catch ThisException and
ThatException as exceptions:
*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
Caught ThisException
In more complicated examples, you may wish to define a whole hierarchy of exceptions:
---------------------------------------------------------------------
-- Make the root exception type for all the exceptions in a compiler
data SomeCompilerException = forall e . Exception e => SomeCompilerException e
instance Show SomeCompilerException where
show (SomeCompilerException e) = show e
instance Exception SomeCompilerException
compilerExceptionToException :: Exception e => e -> SomeException
compilerExceptionToException = toException . SomeCompilerException
compilerExceptionFromException :: Exception e => SomeException -> Maybe e
compilerExceptionFromException x = do
SomeCompilerException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make a subhierarchy for exceptions in the frontend of the compiler
data SomeFrontendException = forall e . Exception e => SomeFrontendException e
instance Show SomeFrontendException where
show (SomeFrontendException e) = show e
instance Exception SomeFrontendException where
toException = compilerExceptionToException
fromException = compilerExceptionFromException
frontendExceptionToException :: Exception e => e -> SomeException
frontendExceptionToException = toException . SomeFrontendException
frontendExceptionFromException :: Exception e => SomeException -> Maybe e
frontendExceptionFromException x = do
SomeFrontendException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make an exception type for a particular frontend compiler exception
data MismatchedParentheses = MismatchedParentheses
deriving Show
instance Exception MismatchedParentheses where
toException = frontendExceptionToException
fromException = frontendExceptionFromExceptionWe can now catch a MismatchedParentheses exception as
MismatchedParentheses, SomeFrontendException or
SomeCompilerException, but not other types, e.g. IOException:
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException))
*** Exception: MismatchedParentheses
Instances
| Exception AesonException | |
Defined in Data.Aeson.Types.Internal Methods toException :: AesonException -> DecodeException -> ParseErrorBundle s e -> String # | |
| (PrettyPlc cause, PrettyPlc err, Typeable cause, Typeable err) => Exception (ErrorWithCause err cause) # | |
Defined in PlutusCore.Evaluation.ErrorWithCause Methods toException :: ErrorWithCause err cause -> SomeException # fromException :: SomeException -> Maybe (ErrorWithCause err cause) # displayException :: ErrorWithCause err cause -> String # | |
| (Reifies s (SomeException -> Maybe a), Typeable a, Typeable s, Typeable m) => Exception (Handling a s m) | |
Defined in Control.Lens.Internal.Exception Methods toException :: Handling a s m -> SomeException # fromException :: SomeException -> Maybe (Handling a s m) # displayException :: Handling a s m -> String # | |
class a ~R# b => Coercible (a :: k) (b :: k) #
Coercible is a two-parameter class that has instances for types a and b if
the compiler can infer that they have the same representation. This class
does not have regular instances; instead they are created on-the-fly during
type-checking. Trying to manually declare an instance of Coercible
is an error.
Nevertheless one can pretend that the following three kinds of instances exist. First, as a trivial base-case:
instance Coercible a a
Furthermore, for every type constructor there is
an instance that allows to coerce under the type constructor. For
example, let D be a prototypical type constructor (data or
newtype) with three type arguments, which have roles nominal,
representational resp. phantom. Then there is an instance of
the form
instance Coercible b b' => Coercible (D a b c) (D a b' c')
Note that the nominal type arguments are equal, the
representational type arguments can differ, but need to have a
Coercible instance themself, and the phantom type arguments can be
changed arbitrarily.
The third kind of instance exists for every newtype NT = MkNT T and
comes in two variants, namely
instance Coercible a T => Coercible a NT
instance Coercible T b => Coercible NT b
This instance is only usable if the constructor MkNT is in scope.
If, as a library author of a type constructor like Set a, you
want to prevent a user of your module to write
coerce :: Set T -> Set NT,
you need to set the role of Set's type parameter to nominal,
by writing
type role Set nominal
For more details about this feature, please refer to Safe Coercions by Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones and Stephanie Weirich.
Since: ghc-prim-0.4.0
The class Typeable allows a concrete representation of a type to
be calculated.
Minimal complete definition
typeRep#
Lens
view :: MonadReader s m => Getting a s a -> m a #
(<^>) :: Fold s a -> Fold s a -> Fold s a infixr 6 #
Compose two folds to make them run in parallel. The results are concatenated.
Debugging
traceShowId :: Show a => a -> a #
Like traceShow but returns the shown value instead of a third value.
>>>traceShowId (1+2+3, "hello" ++ "world")(6,"helloworld") (6,"helloworld")
Since: base-4.7.0.0
The trace function outputs the trace message given as its first argument,
before returning the second argument as its result.
For example, this returns the value of f x and outputs the message to stderr.
Depending on your terminal (settings), they may or may not be mixed.
>>>let x = 123; f = show>>>trace ("calling f with x = " ++ show x) (f x)calling f with x = 123 "123"
The trace function should only be used for debugging, or for monitoring
execution. The function is not referentially transparent: its type indicates
that it is a pure function but it has the side effect of outputting the
trace message.
Reexports from Control.Composition
Custom functions
(<<*>>) :: (Applicative f1, Applicative f2) => f1 (f2 (a -> b)) -> f1 (f2 a) -> f1 (f2 b) infixl 4 #
forJoin :: (Monad m, Traversable m, Applicative f) => m a -> (a -> f (m b)) -> f (m b) #
reoption :: (Foldable f, Alternative g) => f a -> g a #
This function generalizes eitherToMaybe, eitherToList,
listToMaybe and other such functions.
tabulateArray :: (Bounded i, Enum i, Ix i) => (i -> a) -> Array i a #
Basically a Data.Functor.Representable instance for Array.
We can't provide an actual instance because of the Distributive superclass: Array i is not
Distributive unless we assume that indices in an array range over the entirety of i.
(?) :: Alternative f => Bool -> a -> f a infixr 2 #
b ? x is equal to pure x whenever b holds and is empty otherwise.
ensure :: Alternative f => (a -> Bool) -> a -> f a #
ensure p x is equal to pure x whenever p x holds and is empty otherwise.
asksM :: MonadReader r m => (r -> m a) -> m a #
A monadic version of asks.
Pretty-printing
The abstract data type represents pretty documents that have
been annotated with data of type Doc annann.
More specifically, a value of type represents a non-empty set of
possible layouts of a document. The layout functions select one of these
possibilities, taking into account things like the width of the output
document.Doc
The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as
- color information (e.g. when rendering to the terminal)
- mouseover text (e.g. when rendering to rich HTML)
- whether to show something or not (to allow simple or detailed versions)
The simplest way to display a Doc is via the Show class.
>>>putStrLn (show (vsep ["hello", "world"]))hello world
Instances
| Functor Doc | Alter the document’s annotations. This instance makes |
| IsString (Doc ann) |
This instance uses the
|
Defined in hcat [x, y]
| |
Defined in defaultLayoutOptions, ignoring all annotations. | |
Defined in Text)) PageWidth -> Doc ann)))) :+: (C1 ('MetaCons "Nesting" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int -> Doc ann))) :+: C1 ('MetaCons "Annotated" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ann) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann))))))) | |
newtype ShowPretty a #
A newtype wrapper around a whose point is to provide a Show instance
for anything that has a Pretty instance.
Constructors
| ShowPretty | |
Fields
| |
Instances
| Pretty a => Show (ShowPretty a) # | |
Defined in PlutusPrelude Methods showsPrec :: Int -> ShowPretty a -> ShowS # show :: ShowPretty a -> String # showList :: [ShowPretty a] -> ShowS # | |
| Eq a => Eq (ShowPretty a) # | |
Defined in PlutusPrelude | |
Minimal complete definition
Methods
>>>pretty 1 <+> pretty "hello" <+> pretty 1.2341 hello 1.234
prettyList :: [a] -> Doc ann #
is only used to define the prettyListinstance
. In normal circumstances only the Pretty a => Pretty [a]
function is used.pretty
>>>prettyList [1, 23, 456][1, 23, 456]
Instances
| Pretty Void | Finding a good example for printing something that does not exist is hard, so here is an example of printing a list full of nothing.
| |
Defined in Text | Automatically converts all newlines to
Note that
| |
| Pretty Prettyprinter.Internal | ||
| Pretty Integer |
| |
Defined in Prettyprinter.Internal | ||
| Pretty () |
The argument is not used:
| |
Defined in Prettyprinter.Internal | ||
| Pretty Bool |
| |
Defined in line as a more readable alternative.
| ||
Defined in Prettyprinter.Internal | ||
| Pretty Double |
| |
Defined in Prettyprinter.Internal | ||
| Pretty Float |
| |
Defined in Prettyprinter.Internal | ||
| Pretty Int |
| |
Defined in Prettyprinter.Internal | ||
| Pretty a => Pretty (Identity a) |
| |
Defined in Prettyprinter.Internal | ||
| Pretty a => Pretty (Spine a) # |
| |
Defined in PlutusCore.Builtin.KnownType | ||
| Pretty (BuiltinSemanticsVariant DefaultFun) # | ||
Defined in PlutusCore.Default.Builtins Methods pretty :: BuiltinSemanticsVariant DefaultFun -> Doc ann # prettyList :: [BuiltinSemanticsVariant DefaultFun] -> Doc ann # | ||
| Pretty ann => Pretty (Kind ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Default | ||
| Pretty a => Pretty (Normalized a) # | ||
Defined in PlutusCore.Core.Type | ||
| Pretty (DefaultUni a) # | This always pretty-prints parens around type applications (e.g. | |
Defined in PlutusCore.Default.Universe | ||
| Pretty ann => Pretty (UniqueError ann) # | ||
Defined in PlutusCore.Error | ||
| PrettyClassic a => Pretty (EvaluationResult a) # | ||
Defined in PlutusCore.Evaluation.Result | ||
| PrettyReadable a => Pretty (AsReadable a) # | ||
Defined in PlutusCore.Pretty.Readable | ||
| Pretty (SomeTypeIn DefaultUni) # | ||
Defined in PlutusCore.Default.Universe Methods pretty :: SomeTypeIn DefaultUni -> Doc ann # prettyList :: [SomeTypeIn DefaultUni] -> Doc ann # | ||
| Pretty (SomeTypeIn uni) => Pretty (SomeTypeIn (Kinded uni)) # | ||
Defined in PlutusCore.Pretty.PrettyConst Methods pretty :: SomeTypeIn (Kinded uni) -> Doc ann # prettyList :: [SomeTypeIn (Kinded uni)] -> Doc ann # | ||
| (Show fun, Ord fun) => Pretty (CekExTally fun) # | ||
| (Show fun, Ord fun) => Pretty (TallyingSt fun) # | ||
| Show fun => Pretty (ExBudgetCategory fun) # | ||
| Pretty a => Pretty (Maybe a) | Ignore
| |
Defined in Prettyprinter.Internal | ||
| Pretty a => Pretty [a] |
| |
Defined in AttachDefaultPrettyConfig config a] -> Doc ann # | ||
| PrettyBy config a => Pretty (AttachPrettyConfig config a) |
| |
Defined in Text.PrettyBy.Internal Methods pretty :: AttachPrettyConfig config a -> Doc ann # prettyList :: [AttachPrettyConfig config a] -> Doc ann # | ||
| (Closed uni, Everywhere uni PrettyConst) => Pretty (Some (ValueOf uni)) # | ||
| (Pretty a1, Pretty a2) => Pretty (a1, a2) |
| |
Defined in Prettyprinter.Internal | ||
| (Pretty err, Pretty a, Pretty b) => Pretty (HeadSpine err a b) # |
| |
Defined in PlutusCore.Builtin.KnownType | ||
| (PrettyClassic tyname, PrettyParens (SomeTypeIn uni), Pretty ann) => Pretty (Type tyname uni ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Default | ||
| Pretty (CekState uni fun ann) # | ||
| (Pretty a1, Pretty a2, Pretty a3) => Pretty (a1, a2, a3) |
| |
Defined in Prettyprinter.Internal | ||
| (PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Program name uni fun ann) # | ||
| (PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Term name uni fun ann) # | ||
| (PrettyClassic tyname, PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Program tyname name uni fun ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Default | ||
| (PrettyClassic tyname, PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Term tyname name uni fun ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Default | ||
class PrettyBy config a where #
A class for pretty-printing values in a configurable manner.
A basic example:
>>>data Case = UpperCase | LowerCase>>>data D = D>>>instance PrettyBy Case D where prettyBy UpperCase D = "D"; prettyBy LowerCase D = "d">>>prettyBy UpperCase DD>>>prettyBy LowerCase Dd
The library provides instances for common types like Integer or Bool, so you can't define
your own PrettyBy SomeConfig Integer instance. And for the same reason you should not define
instances like PrettyBy SomeAnotherConfig a for universally quantified a, because such an
instance would overlap with the existing ones. Take for example
>>>data ViaShow = ViaShow>>>instance Show a => PrettyBy ViaShow a where prettyBy ViaShow = pretty . show
with such an instance prettyBy ViaShow (1 :: Int) throws an error about overlapping instances:
• Overlapping instances for PrettyBy ViaShow Int
arising from a use of ‘prettyBy’
Matching instances:
instance PrettyDefaultBy config Int => PrettyBy config Int
instance [safe] Show a => PrettyBy ViaShow aThere's a newtype provided specifically for the purpose of defining a PrettyBy instance for
any a: PrettyAny. Read its docs for details on when you might want to use it.
The PrettyBy instance for common types is defined in a way that allows to override default
pretty-printing behaviour, read the docs of HasPrettyDefaults for details.
Minimal complete definition
Nothing
Methods
prettyBy :: config -> a -> Doc ann #
Pretty-print a value of type a the way a config specifies it.
The default implementation of prettyBy is in terms of pretty, defaultPrettyFunctorBy
or defaultPrettyBifunctorBy depending on the kind of the data type that you're providing
an instance for. For example, the default implementation of prettyBy for a monomorphic type
is going to be "ignore the config and call pretty over the value":
>>>newtype N = N Int deriving newtype (Pretty)>>>instance PrettyBy () N>>>prettyBy () (N 42)42
The default implementation of prettyBy for a Functor is going to be in terms of
defaultPrettyFunctorBy:
>>>newtype N a = N a deriving stock (Functor) deriving newtype (Pretty)>>>instance PrettyBy () a => PrettyBy () (N a)>>>prettyBy () (N (42 :: Int))42
It's fine for the data type to have a phantom parameter as long as the data type is still a
defaultPrettyFunctorBy is used
again:
>>>newtype N a = N Int deriving stock (Functor) deriving newtype (Pretty)>>>instance PrettyBy () (N b)>>>prettyBy () (N 42)42
If the data type has a single parameter of any other kind, then it's not a functor and so
like in the monomorphic case pretty is used:
>>>newtype N (b :: Bool) = N Int deriving newtype (Pretty)>>>instance PrettyBy () (N b)>>>prettyBy () (N 42)42
Same applies to a data type with two parameters: if both the parameters are of kind Type,
then the data type is assumed to be a defaultPrettyBifunctorBy is
used. If the right parameter is of kind Type and the left parameter is of any other kind,
then we fallback to assuming the data type is a Functor and defining prettyBy as
defaultPrettyFunctorBy. If both the parameters are not of kind Type, we fallback to
implementing prettyBy in terms of pretty like in the monomorphic case.
Note that in all those cases a Pretty instance for the data type has to already exist,
so that we can derive a PrettyBy one in terms of it. If it doesn't exist or if your data
type is not supported (for example, if it has three or more parameters of kind Type), then
you'll need to provide the implementation manually.
prettyListBy :: config -> [a] -> Doc ann #
prettyListBy is used to define the default PrettyBy instance for [a] and NonEmpty a.
In normal circumstances only the prettyBy function is used.
The default implementation of prettyListBy is in terms of defaultPrettyFunctorBy.
Instances
| PrettyBy PrettyConfigPlc DefaultFun # | ||
Defined in PlutusCore.Default.Builtins Methods prettyBy :: PrettyConfigPlc -> DefaultFun -> Doc ann # prettyListBy :: PrettyConfigPlc -> [DefaultFun] -> Doc ann # | ||
| PrettyBy ConstConfig ByteString # | ||
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> ByteString -> Doc ann # prettyListBy :: ConstConfig -> [ByteString] -> Doc ann # | ||
| PrettyBy ConstConfig Element # | ||
Defined in PlutusCore.Crypto.BLS12_381.G1 Methods prettyBy :: ConstConfig -> Element -> Doc ann # prettyListBy :: ConstConfig -> [Element] -> Doc ann # | ||
| PrettyBy ConstConfig Element # | ||
Defined in PlutusCore.Crypto.BLS12_381.G2 Methods prettyBy :: ConstConfig -> Element -> Doc ann # prettyListBy :: ConstConfig -> [Element] -> Doc ann # | ||
| PrettyBy ConstConfig MlResult # | ||
Defined in PlutusCore.Crypto.BLS12_381.Pairing Methods prettyBy :: ConstConfig -> MlResult -> Doc ann # prettyListBy :: ConstConfig -> [MlResult] -> Doc ann # | ||
| PrettyBy ConstConfig Data # | ||
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> Data -> Doc ann # prettyListBy :: ConstConfig -> [Data] -> Doc ann # | ||
| PrettyBy ConstConfig K # | ||
Defined in PlutusCore.Pretty.PrettyConst | ||
| PrettyBy ConstConfig Quantity # | ||
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> Quantity -> Doc ann # prettyListBy :: ConstConfig -> [Quantity] -> Doc ann # | ||
| PrettyBy ConstConfig Value # | ||
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> Value -> Doc ann # prettyListBy :: ConstConfig -> [Value] -> Doc ann # | ||
| PrettyDefaultBy config Void => PrettyBy config Void |
| |
Defined in Text | Automatically converts all newlines to
| |
| PrettyDefaultBy config Text.PrettyBy.Internal | ||
| PrettyDefaultBy config Integer => PrettyBy config Integer |
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config Natural => PrettyBy config Natural |
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config () => PrettyBy config () |
The argument is not used:
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config Bool => PrettyBy config Bool |
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config Char => PrettyBy config Char | By default a
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config Double => PrettyBy config Double |
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config Float => PrettyBy config Float |
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config Int => PrettyBy config Int |
| |
Defined in RenderContext -> [SomeTypeIn DefaultUni] -> Doc ann # | ||
| PrettyDefaultBy config (Identity a) => PrettyBy config (Identity a) |
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config (NonEmpty a) => PrettyBy config (NonEmpty a) |
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config (Set a) => PrettyBy config (Set a) # | ||
Defined in PlutusCore.Pretty.Extra | ||
| PrettyDefaultBy config (Spine a) => PrettyBy config (Spine a) # | ||
Defined in PlutusCore.Builtin.KnownType | ||
| PrettyBy config (t NameAnn) => PrettyBy config (ScopeCheckError t) # | ||
Defined in PlutusCore.Check.Scoping Methods prettyBy :: config -> ScopeCheckError t -> Doc ann # prettyListBy :: config -> [ScopeCheckError t] -> Doc ann # | ||
| PrettyBy config a => PrettyBy config (Normalized a) # | ||
Defined in PlutusCore.Core.Type Methods prettyBy :: config -> Normalized a -> Doc ann # prettyListBy :: config -> [Normalized a] -> Doc ann # | ||
| (HasPrettyDefaults config ~ 'True, Pretty fun) => PrettyBy config (MachineError fun) # | ||
Defined in PlutusCore.Evaluation.Machine.Exception Methods prettyBy :: config -> MachineError fun -> Doc ann # prettyListBy :: config -> [MachineError fun] -> Doc ann # | ||
| PrettyBy config a => PrettyBy config (EvaluationResult a) # | ||
Defined in PlutusCore.Evaluation.Result Methods prettyBy :: config -> EvaluationResult a -> Doc ann # prettyListBy :: config -> [EvaluationResult a] -> Doc ann # | ||
| PrettyDefaultBy config (AsReadable a) => PrettyBy config (AsReadable a) # | ||
Defined in PlutusCore.Pretty.Readable Methods prettyBy :: config -> AsReadable a -> Doc ann # prettyListBy :: config -> [AsReadable a] -> Doc ann # | ||
| (Show fun, Ord fun) => PrettyBy config (CekExTally fun) # | ||
Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode Methods prettyBy :: config -> CekExTally fun -> Doc ann # prettyListBy :: config -> [CekExTally fun] -> Doc ann # | ||
| (Show fun, Ord fun) => PrettyBy config (TallyingSt fun) # | ||
Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode Methods prettyBy :: config -> TallyingSt fun -> Doc ann # prettyListBy :: config -> [TallyingSt fun] -> Doc ann # | ||
| Pretty a => PrettyBy config (IgnorePrettyConfig a) |
| |
| PrettyDefaultBy config (Maybe a) => PrettyBy config (Maybe a) | By default a
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config [a] => PrettyBy config [a] |
| |
Defined in Text.PrettyBy.Internal | ||
| (PrettyUni uni, Pretty fun) => PrettyBy PrettyConfigPlc (CkValue uni fun) # | ||
Defined in PlutusCore.Evaluation.Machine.Ck Methods prettyBy :: PrettyConfigPlc -> CkValue uni fun -> Doc ann # prettyListBy :: PrettyConfigPlc -> [CkValue uni fun] -> Doc ann # | ||
| (PrettyUni uni, Pretty fun) => PrettyBy PrettyConfigPlc (DischargeResult uni fun) # | ||
Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal Methods prettyBy :: PrettyConfigPlc -> DischargeResult uni fun -> Doc ann # prettyListBy :: PrettyConfigPlc -> [DischargeResult uni fun] -> Doc ann # | ||
| (Closed uni, Everywhere uni PrettyConst) => PrettyBy ConstConfig (ValueOf uni a) # | ||
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> ValueOf uni a -> Doc ann # prettyListBy :: ConstConfig -> [ValueOf uni a] -> Doc ann # | ||
| (Closed uni, Everywhere uni PrettyConst) => PrettyBy ConstConfig (Some (ValueOf uni)) # | ||
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> Some (ValueOf uni) -> Doc ann # prettyListBy :: ConstConfig -> [Some (ValueOf uni)] -> Doc ann # | ||
| PrettyDefaultBy config (Either a b) => PrettyBy config (Either a b) # | An instance extending the set of types supporting default pretty-printing with | |
Defined in PlutusPrelude | ||
| PrettyDefaultBy config (Map k v) => PrettyBy config (Map k v) # | ||
Defined in PlutusCore.Pretty.Extra | ||
| (HasPrettyDefaults config ~ 'True, PrettyBy config structural, Pretty operational) => PrettyBy config (EvaluationError structural operational) # | ||
Defined in PlutusCore.Evaluation.Error Methods prettyBy :: config -> EvaluationError structural operational -> Doc ann # prettyListBy :: config -> [EvaluationError structural operational] -> Doc ann # | ||
| (PrettyBy config cause, PrettyBy config err) => PrettyBy config (ErrorWithCause err cause) # | ||
Defined in PlutusCore.Evaluation.ErrorWithCause Methods prettyBy :: config -> ErrorWithCause err cause -> Doc ann # prettyListBy :: config -> [ErrorWithCause err cause] -> Doc ann # | ||
| PrettyDefaultBy config (a, b) => PrettyBy config (a, b) |
| |
Defined in Text.PrettyBy.Internal | ||
| DefaultPrettyPlcStrategy (Type tyname uni ann) => PrettyBy PrettyConfigPlc (Type tyname uni ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Plc Methods prettyBy :: PrettyConfigPlc -> Type tyname uni ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [Type tyname uni ann] -> Doc ann0 # | ||
| (PrettyUni uni, Pretty fun, Pretty ann) => PrettyBy PrettyConfigPlc (Error uni fun ann) # | ||
Defined in PlutusCore.Error Methods prettyBy :: PrettyConfigPlc -> Error uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [Error uni fun ann] -> Doc ann0 # | ||
| (PrettyUni uni, Pretty fun) => PrettyBy PrettyConfigPlc (CekValue uni fun ann) # | ||
Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal Methods prettyBy :: PrettyConfigPlc -> CekValue uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [CekValue uni fun ann] -> Doc ann0 # | ||
| PrettyDefaultBy config (Const a b) => PrettyBy config (Const a b) | Non-polykinded, because
| |
Defined in Text.PrettyBy.Internal | ||
| PrettyDefaultBy config (HeadSpine err a b) => PrettyBy config (HeadSpine err a b) # | ||
Defined in PlutusCore.Builtin.KnownType | ||
| PrettyDefaultBy config (a, b, c) => PrettyBy config (a, b, c) |
| |
Defined in Text.PrettyBy.Internal | ||
| (Pretty term, PrettyUni uni, Pretty fun, Pretty ann) => PrettyBy PrettyConfigPlc (TypeError term uni fun ann) # | ||
Defined in PlutusCore.Error Methods prettyBy :: PrettyConfigPlc -> TypeError term uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [TypeError term uni fun ann] -> Doc ann0 # | ||
| DefaultPrettyPlcStrategy (UnrestrictedProgram name uni fun ann) => PrettyBy PrettyConfigPlc (UnrestrictedProgram name uni fun ann) # | ||
Defined in UntypedPlutusCore.Core.Instance.Flat Methods prettyBy :: PrettyConfigPlc -> UnrestrictedProgram name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [UnrestrictedProgram name uni fun ann] -> Doc ann0 # | ||
| DefaultPrettyPlcStrategy (Program name uni fun ann) => PrettyBy PrettyConfigPlc (Program name uni fun ann) # | ||
Defined in UntypedPlutusCore.Core.Instance.Pretty.Plc Methods prettyBy :: PrettyConfigPlc -> Program name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [Program name uni fun ann] -> Doc ann0 # | ||
| DefaultPrettyPlcStrategy (Term name uni fun ann) => PrettyBy PrettyConfigPlc (Term name uni fun ann) # | ||
Defined in UntypedPlutusCore.Core.Instance.Pretty.Plc Methods prettyBy :: PrettyConfigPlc -> Term name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [Term name uni fun ann] -> Doc ann0 # | ||
| PrettyBy config (Term name uni fun a) => PrettyBy config (EvalOrder name uni fun a) # | ||
Defined in UntypedPlutusCore.Purity | ||
| PrettyBy config (Term name uni fun a) => PrettyBy config (EvalTerm name uni fun a) # | ||
Defined in UntypedPlutusCore.Purity | ||
| DefaultPrettyPlcStrategy (Program tyname name uni fun ann) => PrettyBy PrettyConfigPlc (Program tyname name uni fun ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Plc Methods prettyBy :: PrettyConfigPlc -> Program tyname name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [Program tyname name uni fun ann] -> Doc ann0 # | ||
| DefaultPrettyPlcStrategy (Term tyname name uni fun ann) => PrettyBy PrettyConfigPlc (Term tyname name uni fun ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Plc Methods prettyBy :: PrettyConfigPlc -> Term tyname name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigPlc -> [Term tyname name uni fun ann] -> Doc ann0 # | ||
| (Pretty ann, PrettyBy config (Type tyname uni ann), PrettyBy config (Term tyname name uni fun ann)) => PrettyBy config (NormCheckError tyname name uni fun ann) # | ||
Defined in PlutusCore.Error Methods prettyBy :: config -> NormCheckError tyname name uni fun ann -> Doc ann0 # prettyListBy :: config -> [NormCheckError tyname name uni fun ann] -> Doc ann0 # | ||
| Pretty ann => PrettyBy (PrettyConfigClassic configName) (Kind ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Classic Methods prettyBy :: PrettyConfigClassic configName -> Kind ann -> Doc ann0 # prettyListBy :: PrettyConfigClassic configName -> [Kind ann] -> Doc ann0 # | ||
| PrettyBy (PrettyConfigReadable configName) (Kind a) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> Kind a -> Doc ann # prettyListBy :: PrettyConfigReadable configName -> [Kind a] -> Doc ann # | ||
| PrettyReadableBy configName a => PrettyBy (PrettyConfigReadable configName) (Parened a) # | ||
Defined in PlutusCore.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> Parened a -> Doc ann # prettyListBy :: PrettyConfigReadable configName -> [Parened a] -> Doc ann # | ||
| PrettyReadableBy configName tyname => PrettyBy (PrettyConfigReadable configName) (TyVarDecl tyname ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> TyVarDecl tyname ann -> Doc ann0 # prettyListBy :: PrettyConfigReadable configName -> [TyVarDecl tyname ann] -> Doc ann0 # | ||
| (PrettyClassicBy configName tyname, PrettyParens (SomeTypeIn uni), Pretty ann) => PrettyBy (PrettyConfigClassic configName) (Type tyname uni ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Classic Methods prettyBy :: PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann0 # prettyListBy :: PrettyConfigClassic configName -> [Type tyname uni ann] -> Doc ann0 # | ||
| (PrettyReadableBy configName tyname, PrettyParens (SomeTypeIn uni)) => PrettyBy (PrettyConfigReadable configName) (Type tyname uni a) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> Type tyname uni a -> Doc ann # prettyListBy :: PrettyConfigReadable configName -> [Type tyname uni a] -> Doc ann # | ||
| (PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => PrettyBy (PrettyConfigClassic PrettyConfigName) (UnrestrictedProgram name uni fun ann) # | ||
Defined in UntypedPlutusCore.Core.Instance.Flat Methods prettyBy :: PrettyConfigClassic PrettyConfigName -> UnrestrictedProgram name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigClassic PrettyConfigName -> [UnrestrictedProgram name uni fun ann] -> Doc ann0 # | ||
| (PrettyClassicBy configName (Term name uni fun ann), Pretty ann) => PrettyBy (PrettyConfigClassic configName) (Program name uni fun ann) # | ||
Defined in UntypedPlutusCore.Core.Instance.Pretty.Classic Methods prettyBy :: PrettyConfigClassic configName -> Program name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigClassic configName -> [Program name uni fun ann] -> Doc ann0 # | ||
| (PrettyClassicBy configName name, PrettyUni uni, Pretty fun, Pretty ann) => PrettyBy (PrettyConfigClassic configName) (Term name uni fun ann) # | ||
Defined in UntypedPlutusCore.Core.Instance.Pretty.Classic Methods prettyBy :: PrettyConfigClassic configName -> Term name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigClassic configName -> [Term name uni fun ann] -> Doc ann0 # | ||
| (PrettyReadable name, PrettyUni uni, Pretty fun) => PrettyBy (PrettyConfigReadable PrettyConfigName) (UnrestrictedProgram name uni fun ann) # | ||
Defined in UntypedPlutusCore.Core.Instance.Flat Methods prettyBy :: PrettyConfigReadable PrettyConfigName -> UnrestrictedProgram name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigReadable PrettyConfigName -> [UnrestrictedProgram name uni fun ann] -> Doc ann0 # | ||
| (PrettyReadableBy configName tyname, PrettyReadableBy configName name, PrettyUni uni) => PrettyBy (PrettyConfigReadable configName) (VarDecl tyname name uni ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> VarDecl tyname name uni ann -> Doc ann0 # prettyListBy :: PrettyConfigReadable configName -> [VarDecl tyname name uni ann] -> Doc ann0 # | ||
| PrettyReadableBy configName (Term name uni fun a) => PrettyBy (PrettyConfigReadable configName) (Program name uni fun a) # | ||
Defined in UntypedPlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> Program name uni fun a -> Doc ann # prettyListBy :: PrettyConfigReadable configName -> [Program name uni fun a] -> Doc ann # | ||
| (PrettyReadableBy configName name, PrettyUni uni, Pretty fun, Show configName) => PrettyBy (PrettyConfigReadable configName) (Term name uni fun a) # | ||
Defined in UntypedPlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> Term name uni fun a -> Doc ann # prettyListBy :: PrettyConfigReadable configName -> [Term name uni fun a] -> Doc ann # | ||
| (PrettyClassicBy configName (Term tyname name uni fun ann), Pretty ann) => PrettyBy (PrettyConfigClassic configName) (Program tyname name uni fun ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Classic Methods prettyBy :: PrettyConfigClassic configName -> Program tyname name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigClassic configName -> [Program tyname name uni fun ann] -> Doc ann0 # | ||
| (PrettyClassicBy configName tyname, PrettyClassicBy configName name, PrettyUni uni, Pretty fun, Pretty ann) => PrettyBy (PrettyConfigClassic configName) (Term tyname name uni fun ann) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Classic Methods prettyBy :: PrettyConfigClassic configName -> Term tyname name uni fun ann -> Doc ann0 # prettyListBy :: PrettyConfigClassic configName -> [Term tyname name uni fun ann] -> Doc ann0 # | ||
| PrettyReadableBy configName (Term tyname name uni fun a) => PrettyBy (PrettyConfigReadable configName) (Program tyname name uni fun a) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> Program tyname name uni fun a -> Doc ann # prettyListBy :: PrettyConfigReadable configName -> [Program tyname name uni fun a] -> Doc ann # | ||
| (PrettyReadableBy configName tyname, PrettyReadableBy configName name, PrettyUni uni, Pretty fun) => PrettyBy (PrettyConfigReadable configName) (Term tyname name uni fun a) # | ||
Defined in PlutusCore.Core.Instance.Pretty.Readable Methods prettyBy :: PrettyConfigReadable configName -> Term tyname name uni fun a -> Doc ann # prettyListBy :: PrettyConfigReadable configName -> [Term tyname name uni fun a] -> Doc ann # | ||
type family HasPrettyDefaults config :: Bool #
Determines whether a pretty-printing config allows default pretty-printing for types that support it. I.e. it's possible to create a new config and get access to pretty-printing for all types supporting default pretty-printing just by providing the right type instance. Example:
>>>data DefCfg = DefCfg>>>type instance HasPrettyDefaults DefCfg = 'True>>>prettyBy DefCfg (['a', 'b', 'c'], (1 :: Int), Just True)(abc, 1, True)
The set of types supporting default pretty-printing is determined by the prettyprinter
library: whatever there has a Pretty instance also supports default pretty-printing
in this library and the behavior of pretty x and prettyBy config_with_defaults x must
be identical when x is one of such types.
It is possible to override default pretty-printing. For this you need to specify that
HasPrettyDefaults is 'False for your config and then define a NonDefaultPrettyBy config
instance for each of the types supporting default pretty-printing that you want to pretty-print
values of. Note that once HasPrettyDefaults is specified to be 'False,
all defaults are lost for your config, so you can't override default pretty-printing for one
type and keep the defaults for all the others. I.e. if you have
>>>data NonDefCfg = NonDefCfg>>>type instance HasPrettyDefaults NonDefCfg = 'False
then you have no defaults available and an attempt to pretty-print a value of a type supporting default pretty-printing
prettyBy NonDefCfg True
results in a type error:
• No instance for (NonDefaultPrettyBy NonDef Bool)
arising from a use of ‘prettyBy’As the error suggests you need to provide a NonDefaultPrettyBy instance explicitly:
>>>instance NonDefaultPrettyBy NonDefCfg Bool where nonDefaultPrettyBy _ b = if b then "t" else "f">>>prettyBy NonDefCfg Truet
It is also possible not to provide any implementation for nonDefaultPrettyBy, in which case
it defaults to being the default pretty-printing for the given type. This can be useful to
recover default pretty-printing for types pretty-printing of which you don't want to override:
>>>instance NonDefaultPrettyBy NonDefCfg Int>>>prettyBy NonDefCfg (42 :: Int)42
Look into test/NonDefault.hs for an extended example.
We could give the user more fine-grained control over what defaults to override instead of requiring to explicitly provide all the instances whenever there's a need to override any default behavior, but that would complicate the library even more, so we opted for not doing that at the moment.
Note that you can always override default behavior by wrapping a type in newtype and
providing a PrettyBy config_name instance for that newtype.
Also note that if you want to extend the set of types supporting default pretty-printing
it's not enough to provide a Pretty instance for your type (such logic is hardly expressible
in present day Haskell). Read the docs of DefaultPrettyBy for how to extend the set of types
supporting default pretty-printing.
Instances
| type HasPrettyDefaults PrettyConfigName # | |||||
Defined in PlutusCore.Pretty.ConfigName type HasPrettyDefaults PrettyConfigName = 'NonStuckHasPrettyDefaults config) config #
A
or you can use the type to via-derive instances:
One important use case is handling sum-type configs. For example having two configs you can
define their sum and derive
Then having a data type implementing both
Look into Constructors
Instances | |||||