{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MonoLocalBinds        #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TypeOperators         #-}
{-# LANGUAGE UndecidableInstances  #-}
{-# OPTIONS_GHC -Wno-orphans       #-}

module PlutusIR.Core.Instance.Pretty () where

import PlutusPrelude

import PlutusCore qualified as PLC
import PlutusCore.Flat ()
import PlutusCore.Pretty qualified as PLC

import PlutusIR.Core.Instance.Pretty.Readable ()
import PlutusIR.Core.Type

import Prettyprinter
import Prettyprinter.Custom

-- Pretty-printing

instance ( PLC.PrettyClassicBy configName tyname
         , PLC.PrettyClassicBy configName name
         , PLC.PrettyParens (PLC.SomeTypeIn uni)
         , Pretty ann
         ) => PrettyBy (PLC.PrettyConfigClassic configName) (VarDecl tyname name uni ann) where
    prettyBy :: forall ann.
PrettyConfigClassic configName
-> VarDecl tyname name uni ann -> Doc ann
prettyBy PrettyConfigClassic configName
config (VarDecl ann
ann name
n Type tyname uni ann
ty) =
        Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"vardecl" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann [PrettyConfigClassic configName -> name -> Doc ann
forall ann. PrettyConfigClassic configName -> name -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config name
n, PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty])

instance ( PLC.PrettyClassicBy configName tyname
         , Pretty ann
         ) => PrettyBy (PLC.PrettyConfigClassic configName) (TyVarDecl tyname ann) where
    prettyBy :: forall ann.
PrettyConfigClassic configName -> TyVarDecl tyname ann -> Doc ann
prettyBy PrettyConfigClassic configName
config (TyVarDecl ann
ann tyname
n Kind ann
ty) =
        Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"tyvardecl" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann [PrettyConfigClassic configName -> tyname -> Doc ann
forall ann. PrettyConfigClassic configName -> tyname -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config tyname
n, PrettyConfigClassic configName -> Kind ann -> Doc ann
forall ann. PrettyConfigClassic configName -> Kind ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Kind ann
ty])

instance PrettyBy (PLC.PrettyConfigClassic configName) Recursivity where
    prettyBy :: forall ann.
PrettyConfigClassic configName -> Recursivity -> Doc ann
prettyBy PrettyConfigClassic configName
_ = \case
        Recursivity
NonRec -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
parens Doc ann
"nonrec"
        Recursivity
Rec    -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
parens Doc ann
"rec"

instance PrettyBy (PLC.PrettyConfigClassic configName) Strictness where
    prettyBy :: forall ann. PrettyConfigClassic configName -> Strictness -> Doc ann
prettyBy PrettyConfigClassic configName
_ = \case
        Strictness
NonStrict -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
parens Doc ann
"nonstrict"
        Strictness
Strict    -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
parens Doc ann
"strict"

instance ( PLC.PrettyClassicBy configName tyname
         , PLC.PrettyClassicBy configName name
         , PLC.PrettyParens (PLC.SomeTypeIn uni)
         , Pretty ann
         ) => PrettyBy (PLC.PrettyConfigClassic configName) (Datatype tyname name uni ann) where
    prettyBy :: forall ann.
PrettyConfigClassic configName
-> Datatype tyname name uni ann -> Doc ann
prettyBy PrettyConfigClassic configName
config (Datatype ann
ann TyVarDecl tyname ann
ty [TyVarDecl tyname ann]
tyvars name
destr [VarDecl tyname name uni ann]
constrs) =
        Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"datatype" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
            [ PrettyConfigClassic configName -> TyVarDecl tyname ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> TyVarDecl tyname ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config TyVarDecl tyname ann
ty
            , [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
sep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ (TyVarDecl tyname ann -> Doc ann)
-> [TyVarDecl tyname ann] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PrettyConfigClassic configName -> TyVarDecl tyname ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> TyVarDecl tyname ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config) [TyVarDecl tyname ann]
tyvars
            , PrettyConfigClassic configName -> name -> Doc ann
forall ann. PrettyConfigClassic configName -> name -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config name
destr
            , [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
sep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ (VarDecl tyname name uni ann -> Doc ann)
-> [VarDecl tyname name uni ann] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PrettyConfigClassic configName
-> VarDecl tyname name uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> VarDecl tyname name uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config) [VarDecl tyname name uni ann]
constrs
            ])

instance ( PLC.PrettyClassicBy configName tyname
         , PLC.PrettyClassicBy configName name
         , PLC.PrettyUni uni
         , Pretty fun
         , Pretty ann
         ) => PrettyBy (PLC.PrettyConfigClassic configName) (Binding tyname name uni fun ann) where
    prettyBy :: forall ann.
PrettyConfigClassic configName
-> Binding tyname name uni fun ann -> Doc ann
prettyBy PrettyConfigClassic configName
config = \case
        TermBind ann
ann Strictness
s VarDecl tyname name uni ann
d Term tyname name uni fun ann
t ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"termbind" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> Strictness -> Doc ann
forall ann. PrettyConfigClassic configName -> Strictness -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Strictness
s, PrettyConfigClassic configName
-> VarDecl tyname name uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> VarDecl tyname name uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config VarDecl tyname name uni ann
d, PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t])
        TypeBind ann
ann TyVarDecl tyname ann
d Type tyname uni ann
ty  ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"typebind" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> TyVarDecl tyname ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> TyVarDecl tyname ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config TyVarDecl tyname ann
d, PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty])
        DatatypeBind ann
ann Datatype tyname name uni ann
d ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"datatypebind" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName
-> Datatype tyname name uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Datatype tyname name uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Datatype tyname name uni ann
d])

instance ( PLC.PrettyClassicBy configName tyname
         , PLC.PrettyClassicBy configName name
         , PLC.PrettyUni uni
         , Pretty fun
         , Pretty ann
         ) => PrettyBy (PLC.PrettyConfigClassic configName) (Term tyname name uni fun ann) where
    prettyBy :: forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
prettyBy PrettyConfigClassic configName
config = \case
        Let ann
ann Recursivity
r NonEmpty (Binding tyname name uni fun ann)
bs Term tyname name uni fun ann
t ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"let" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> Recursivity -> Doc ann
forall ann.
PrettyConfigClassic configName -> Recursivity -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Recursivity
r, [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
sep ([Doc ann] -> Doc ann)
-> (NonEmpty (Doc ann) -> [Doc ann])
-> NonEmpty (Doc ann)
-> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Doc ann) -> [Doc ann]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (NonEmpty (Doc ann) -> Doc ann) -> NonEmpty (Doc ann) -> Doc ann
forall a b. (a -> b) -> a -> b
$ (Binding tyname name uni fun ann -> Doc ann)
-> NonEmpty (Binding tyname name uni fun ann) -> NonEmpty (Doc ann)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PrettyConfigClassic configName
-> Binding tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Binding tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config) NonEmpty (Binding tyname name uni fun ann)
bs, PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t])
        Var ann
ann name
n ->
            [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
sep (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> name -> Doc ann
forall ann. PrettyConfigClassic configName -> name -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config name
n])
        TyAbs ann
ann tyname
tn Kind ann
k Term tyname name uni fun ann
t ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"abs" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> tyname -> Doc ann
forall ann. PrettyConfigClassic configName -> tyname -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config tyname
tn, PrettyConfigClassic configName -> Kind ann -> Doc ann
forall ann. PrettyConfigClassic configName -> Kind ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Kind ann
k, PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t])
        LamAbs ann
ann name
n Type tyname uni ann
ty Term tyname name uni fun ann
t ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"lam" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> name -> Doc ann
forall ann. PrettyConfigClassic configName -> name -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config name
n, PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty, PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t])
        Apply ann
ann Term tyname name uni fun ann
t1 Term tyname name uni fun ann
t2 ->
            Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
brackets' ([Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
sep (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t1, PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t2]))
        Constant ann
ann Some (ValueOf uni)
c ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"con" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann [Some (ValueOf uni) -> Doc ann
forall dann. Some (ValueOf uni) -> Doc dann
prettyTypeOf Some (ValueOf uni)
c, Some (ValueOf uni) -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall dann. Some (ValueOf uni) -> Doc dann
pretty Some (ValueOf uni)
c])
        Builtin ann
ann fun
bi ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"builtin" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [fun -> Doc ann
forall ann. fun -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty fun
bi])
        TyInst ann
ann Term tyname name uni fun ann
t Type tyname uni ann
ty ->
            Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
braces' ([Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
sep (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t, PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty]))
        Error ann
ann Type tyname uni ann
ty ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"error" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty])
        IWrap ann
ann Type tyname uni ann
ty1 Type tyname uni ann
ty2 Term tyname name uni fun ann
t ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"iwrap" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty1, PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty2, PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t])
        Unwrap ann
ann Term tyname name uni fun ann
t ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"unwrap" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                [PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t])
        Constr ann
ann Type tyname uni ann
ty Word64
i [Term tyname name uni fun ann]
es ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"constr" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                           (PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
: Word64 -> Doc ann
forall ann. Word64 -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Word64
i Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
: (Term tyname name uni fun ann -> Doc ann)
-> [Term tyname name uni fun ann] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config) [Term tyname name uni fun ann]
es))
        Case ann
ann Type tyname uni ann
ty Term tyname name uni fun ann
arg [Term tyname name uni fun ann]
cs ->
            Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"case" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann
                         (PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall ann.
PrettyConfigClassic configName -> Type tyname uni ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Type tyname uni ann
ty Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
: PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
arg Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
: (Term tyname name uni fun ann -> Doc ann)
-> [Term tyname name uni fun ann] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config) [Term tyname name uni fun ann]
cs))
      where
        prettyTypeOf :: PLC.Some (PLC.ValueOf uni) -> Doc dann
        prettyTypeOf :: forall dann. Some (ValueOf uni) -> Doc dann
prettyTypeOf (PLC.Some (PLC.ValueOf uni (Esc a)
uni a
_ )) =
            RenderContext -> SomeTypeIn uni -> Doc dann
forall ann. RenderContext -> SomeTypeIn uni -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
PLC.prettyBy RenderContext
PLC.juxtRenderContext (SomeTypeIn uni -> Doc dann) -> SomeTypeIn uni -> Doc dann
forall a b. (a -> b) -> a -> b
$ uni (Esc a) -> SomeTypeIn uni
forall (uni :: * -> *) k (a :: k). uni (Esc a) -> SomeTypeIn uni
PLC.SomeTypeIn uni (Esc a)
uni


instance ( PLC.PrettyClassicBy configName tyname
         , PLC.PrettyClassicBy configName name
         , PLC.PrettyUni uni
         , Pretty fun
         , Pretty ann
         ) => PrettyBy (PLC.PrettyConfigClassic configName) (Program tyname name uni fun ann) where
    prettyBy :: forall ann.
PrettyConfigClassic configName
-> Program tyname name uni fun ann -> Doc ann
prettyBy PrettyConfigClassic configName
config (Program ann
ann Version
v Term tyname name uni fun ann
t) =
        Doc ann -> [Doc ann] -> Doc ann
forall a. Doc a -> [Doc a] -> Doc a
sexp Doc ann
"program" (PrettyConfigClassic configName -> ann -> [Doc ann] -> [Doc ann]
forall ann configName dann.
Pretty ann =>
PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
PLC.consAnnIf PrettyConfigClassic configName
config ann
ann [Version -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Version -> Doc ann
pretty Version
v, PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall ann.
PrettyConfigClassic configName
-> Term tyname name uni fun ann -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic configName
config Term tyname name uni fun ann
t])

instance (PLC.PrettyClassic tyname, Pretty ann) =>
    Pretty (TyVarDecl tyname ann) where
    pretty :: forall ann. TyVarDecl tyname ann -> Doc ann
pretty = TyVarDecl tyname ann -> Doc ann
forall a ann. PrettyClassic a => a -> Doc ann
PLC.prettyClassic

instance ( PLC.PrettyClassic tyname
         , PLC.PrettyClassic name
         , PLC.PrettyParens (PLC.SomeTypeIn uni)
         , Pretty ann
         ) => Pretty (VarDecl tyname name uni ann) where
    pretty :: forall ann. VarDecl tyname name uni ann -> Doc ann
pretty = VarDecl tyname name uni ann -> Doc ann
forall a ann. PrettyClassic a => a -> Doc ann
PLC.prettyClassic

instance ( PLC.PrettyClassic tyname
         , PLC.PrettyClassic name
         , PLC.PrettyUni uni
         , Pretty ann
         ) => Pretty (Datatype tyname name uni ann) where
    pretty :: forall ann. Datatype tyname name uni ann -> Doc ann
pretty = Datatype tyname name uni ann -> Doc ann
forall a ann. PrettyClassic a => a -> Doc ann
PLC.prettyClassic

instance ( PLC.PrettyClassic tyname
         , PLC.PrettyClassic name
         , PLC.PrettyUni uni
         , Pretty fun
         , Pretty ann
         ) => Pretty (Binding tyname name uni fun ann) where
    pretty :: forall ann. Binding tyname name uni fun ann -> Doc ann
pretty = Binding tyname name uni fun ann -> Doc ann
forall a ann. PrettyClassic a => a -> Doc ann
PLC.prettyClassic

instance ( PLC.PrettyClassic tyname
         , PLC.PrettyClassic name
         , PLC.PrettyUni uni
         , Pretty fun
         , Pretty ann
         ) => Pretty (Term tyname name uni fun ann) where
    pretty :: forall ann. Term tyname name uni fun ann -> Doc ann
pretty = Term tyname name uni fun ann -> Doc ann
forall a ann. PrettyClassic a => a -> Doc ann
PLC.prettyClassic

instance ( PLC.PrettyClassic tyname
         , PLC.PrettyClassic name
         , PLC.PrettyUni uni
         , Pretty fun
         , Pretty ann
         ) => Pretty (Program tyname name uni fun ann) where
    pretty :: forall ann. Program tyname name uni fun ann -> Doc ann
pretty = Program tyname name uni fun ann -> Doc ann
forall a ann. PrettyClassic a => a -> Doc ann
PLC.prettyClassic


deriving via PrettyAny (Term tyname name uni fun ann)
    instance PLC.DefaultPrettyPlcStrategy (Term tyname name uni fun ann) =>
        PrettyBy PLC.PrettyConfigPlc (Term tyname name uni fun ann)

deriving via PrettyAny (Program tyname name uni fun ann)
    instance PLC.DefaultPrettyPlcStrategy (Program tyname name uni fun ann) =>
        PrettyBy PLC.PrettyConfigPlc (Program tyname name uni fun ann)