{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

module Unison.Runtime.IOSource where

import Control.Lens (_2)
import Control.Monad.Morph (hoist)
import Data.List (elemIndex, genericIndex)
import Data.Map qualified as Map
import Data.Text qualified as Text
import Text.RawString.QQ (r)
import Unison.Builtin qualified as Builtin
import Unison.Codebase.CodeLookup (CodeLookup (..))
import Unison.Codebase.CodeLookup.Util qualified as CL
import Unison.ConstructorReference (GConstructorReference (..))
import Unison.DataDeclaration qualified as DD
import Unison.DataDeclaration.ConstructorId qualified as DD
import Unison.FileParsers (ShouldUseTndr (..), computeTypecheckingEnvironment, synthesizeFile)
import Unison.Parser.Ann (Ann (..))
import Unison.Parsers qualified as Parsers
import Unison.Prelude
import Unison.PrettyPrintEnv qualified as PPE
import Unison.PrettyPrintEnv.Names qualified as PPE
import Unison.PrintError qualified as PrintError
import Unison.Reference qualified as R
import Unison.Result qualified as Result
import Unison.Symbol (Symbol)
import Unison.Syntax.Parser qualified as Parser
import Unison.Term qualified as Term
import Unison.Typechecker qualified as Typechecker
import Unison.UnisonFile qualified as UF
import Unison.Util.Monoid (intercalateMap)
import Unison.Util.Pretty qualified as Pretty
import Unison.Var qualified as Var

debug :: Bool
debug :: Bool
debug = Bool
False

parsingEnv :: Parser.ParsingEnv Identity
parsingEnv :: ParsingEnv Identity
parsingEnv =
  Parser.ParsingEnv
    { $sel:uniqueNames:ParsingEnv :: UniqueName
uniqueNames = UniqueName
forall a. Monoid a => a
mempty,
      $sel:uniqueTypeGuid:ParsingEnv :: Name -> Identity (Maybe Text)
uniqueTypeGuid = \Name
_ -> Maybe Text -> Identity (Maybe Text)
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Text
forall a. Maybe a
Nothing,
      $sel:names:ParsingEnv :: Names
names = Names
Builtin.names,
      $sel:maybeNamespace:ParsingEnv :: Maybe Name
maybeNamespace = Maybe Name
forall a. Maybe a
Nothing,
      $sel:localNamespacePrefixedTypesAndConstructors:ParsingEnv :: Names
localNamespacePrefixedTypesAndConstructors = Names
forall a. Monoid a => a
mempty
    }

typecheckingEnv :: Typechecker.Env Symbol Ann
typecheckingEnv :: Env Symbol Ann
typecheckingEnv =
  Identity (Env Symbol Ann) -> Env Symbol Ann
forall a. Identity a -> a
runIdentity do
    ShouldUseTndr Identity
-> [Type Symbol Ann]
-> (DefnsF Set Reference Reference
    -> Identity (TypeLookup Symbol Ann))
-> UnisonFile Symbol
-> Identity (Env Symbol Ann)
forall v (m :: * -> *).
(Var v, Monad m) =>
ShouldUseTndr m
-> [Type v]
-> (DefnsF Set Reference Reference -> m (TypeLookup v Ann))
-> UnisonFile v
-> m (Env v Ann)
computeTypecheckingEnvironment
      (ParsingEnv Identity -> ShouldUseTndr Identity
forall (m :: * -> *). ParsingEnv m -> ShouldUseTndr m
ShouldUseTndr'Yes ParsingEnv Identity
parsingEnv)
      []
      (\DefnsF Set Reference Reference
_ -> TypeLookup Symbol Ann -> Identity (TypeLookup Symbol Ann)
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ann
External Ann -> TypeLookup Symbol Ann -> TypeLookup Symbol Ann
forall a b. a -> TypeLookup Symbol b -> TypeLookup Symbol a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ TypeLookup Symbol Ann
Builtin.typeLookup))
      UnisonFile Symbol
parsedFile

parsedFile :: UF.UnisonFile Symbol Ann
parsedFile :: UnisonFile Symbol
parsedFile =
  case Identity (Either (Err Symbol) (UnisonFile Symbol))
-> Either (Err Symbol) (UnisonFile Symbol)
forall a. Identity a -> a
runIdentity ([Char]
-> [Char]
-> ParsingEnv Identity
-> Identity (Either (Err Symbol) (UnisonFile Symbol))
forall (m :: * -> *) v.
(Monad m, Var v) =>
[Char]
-> [Char] -> ParsingEnv m -> m (Either (Err v) (UnisonFile v Ann))
Parsers.parseFile [Char]
"<IO.u builtin>" [Char]
sourceString ParsingEnv Identity
parsingEnv) of
    Left Err Symbol
err -> [Char] -> UnisonFile Symbol
forall a. HasCallStack => [Char] -> a
error (Pretty ColorText -> [Char]
Pretty.toAnsiUnbroken ([Char] -> Err Symbol -> Pretty ColorText
forall v. Var v => [Char] -> Err v -> Pretty ColorText
PrintError.prettyParseError [Char]
sourceString Err Symbol
err))
    Right UnisonFile Symbol
file -> UnisonFile Symbol
file

typecheckedFile :: UF.TypecheckedUnisonFile Symbol Ann
typecheckedFile :: TypecheckedUnisonFile Symbol Ann
typecheckedFile =
  let x :: TypecheckedUnisonFile Symbol Ann
x = TypecheckedUnisonFile Symbol Ann
typecheckedFile'
   in if Bool
debug then [Char]
-> TypecheckedUnisonFile Symbol Ann
-> TypecheckedUnisonFile Symbol Ann
forall a. [Char] -> a -> a
trace ([Char]
"IOSource.typecheckedFile = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ TypecheckedUnisonFile Symbol Ann -> [Char]
forall a. Show a => a -> [Char]
show TypecheckedUnisonFile Symbol Ann
x) TypecheckedUnisonFile Symbol Ann
x else TypecheckedUnisonFile Symbol Ann
x

typecheckedFile' :: UF.TypecheckedUnisonFile Symbol Ann
typecheckedFile' :: TypecheckedUnisonFile Symbol Ann
typecheckedFile' =
  case Env Symbol Ann
-> UnisonFile Symbol
-> ResultT
     (Seq (Note Symbol Ann)) Identity (TypecheckedUnisonFile Symbol Ann)
forall (m :: * -> *) v.
(Monad m, Var v) =>
Env v Ann
-> UnisonFile v
-> ResultT (Seq (Note v Ann)) m (TypecheckedUnisonFile v Ann)
synthesizeFile Env Symbol Ann
typecheckingEnv UnisonFile Symbol
parsedFile of
    Result.Result Seq (Note Symbol Ann)
notes Maybe (TypecheckedUnisonFile Symbol Ann)
Nothing -> [Char] -> TypecheckedUnisonFile Symbol Ann
forall a. HasCallStack => [Char] -> a
error ([Char] -> Env -> Seq (Note Symbol Ann) -> [Char]
forall (f :: * -> *).
Foldable f =>
[Char] -> Env -> f (Note Symbol Ann) -> [Char]
showNotes [Char]
sourceString Env
ppEnv Seq (Note Symbol Ann)
notes)
    Result.Result Seq (Note Symbol Ann)
_ (Just TypecheckedUnisonFile Symbol Ann
file) -> TypecheckedUnisonFile Symbol Ann
file

typecheckedFileTerms :: Map.Map Symbol R.Reference
typecheckedFileTerms :: Map Symbol Reference
typecheckedFileTerms = Getting
  Reference
  (Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
  Reference
-> (Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
-> Reference
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting
  Reference
  (Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
  Reference
forall s t a b. Field2 s t a b => Lens s t a b
Lens
  (Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
  (Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
  Reference
  Reference
_2 ((Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
 -> Reference)
-> Map
     Symbol
     (Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
-> Map Symbol Reference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TypecheckedUnisonFile Symbol Ann
-> Map
     Symbol
     (Ann, Reference, Maybe [Char], Term Symbol Ann, Type Symbol Ann)
forall v a.
TypecheckedUnisonFile v a
-> Map v (a, Reference, Maybe [Char], Term v a, Type v a)
UF.hashTerms TypecheckedUnisonFile Symbol Ann
typecheckedFile

termNamed :: String -> R.Reference
termNamed :: [Char] -> Reference
termNamed [Char]
s =
  Reference -> Maybe Reference -> Reference
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> Reference
forall a. HasCallStack => [Char] -> a
error ([Char] -> Reference) -> [Char] -> Reference
forall a b. (a -> b) -> a -> b
$ [Char]
"No builtin term called: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
s) (Maybe Reference -> Reference) -> Maybe Reference -> Reference
forall a b. (a -> b) -> a -> b
$
    Symbol -> Map Symbol Reference -> Maybe Reference
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ([Char] -> Symbol
forall v. Var v => [Char] -> v
Var.nameds [Char]
s) Map Symbol Reference
typecheckedFileTerms

codeLookup :: CodeLookup Symbol Identity Ann
codeLookup :: CodeLookup Symbol Identity Ann
codeLookup = TypecheckedUnisonFile Symbol Ann -> CodeLookup Symbol Identity Ann
forall (m :: * -> *) v a.
(Var v, Monad m) =>
TypecheckedUnisonFile v a -> CodeLookup v m a
CL.fromTypecheckedUnisonFile TypecheckedUnisonFile Symbol Ann
typecheckedFile

codeLookupM :: (Applicative m) => CodeLookup Symbol m Ann
codeLookupM :: forall (m :: * -> *). Applicative m => CodeLookup Symbol m Ann
codeLookupM = (forall a. Identity a -> m a)
-> CodeLookup Symbol Identity Ann -> CodeLookup Symbol m Ann
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
       (b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
forall (m :: * -> *) (n :: * -> *) b.
Monad m =>
(forall a. m a -> n a)
-> CodeLookup Symbol m b -> CodeLookup Symbol n b
hoist (a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> m a) -> (Identity a -> a) -> Identity a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity a -> a
forall a. Identity a -> a
runIdentity) CodeLookup Symbol Identity Ann
codeLookup

typeNamedId :: String -> R.Id
typeNamedId :: [Char] -> Id
typeNamedId [Char]
s =
  case Symbol
-> Map Symbol (Id, DataDeclaration Symbol Ann)
-> Maybe (Id, DataDeclaration Symbol Ann)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ([Char] -> Symbol
forall v. Var v => [Char] -> v
Var.nameds [Char]
s) (TypecheckedUnisonFile Symbol Ann
-> Map Symbol (Id, DataDeclaration Symbol Ann)
forall v a.
TypecheckedUnisonFile v a -> Map v (Id, DataDeclaration v a)
UF.dataDeclarationsId' TypecheckedUnisonFile Symbol Ann
typecheckedFile) of
    Maybe (Id, DataDeclaration Symbol Ann)
Nothing -> [Char] -> Id
forall a. HasCallStack => [Char] -> a
error ([Char] -> Id) -> [Char] -> Id
forall a b. (a -> b) -> a -> b
$ [Char]
"No builtin type called: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
s
    Just (Id
r, DataDeclaration Symbol Ann
_) -> Id
r

typeNamed :: String -> R.Reference
typeNamed :: [Char] -> Reference
typeNamed = Id -> Reference
forall h t. Id' h -> Reference' t h
R.DerivedId (Id -> Reference) -> ([Char] -> Id) -> [Char] -> Reference
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Id
typeNamedId

abilityNamedId :: String -> R.Id
abilityNamedId :: [Char] -> Id
abilityNamedId [Char]
s =
  case Symbol
-> Map Symbol (Id, EffectDeclaration Symbol Ann)
-> Maybe (Id, EffectDeclaration Symbol Ann)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ([Char] -> Symbol
forall v. Var v => [Char] -> v
Var.nameds [Char]
s) (TypecheckedUnisonFile Symbol Ann
-> Map Symbol (Id, EffectDeclaration Symbol Ann)
forall v a.
TypecheckedUnisonFile v a -> Map v (Id, EffectDeclaration v a)
UF.effectDeclarationsId' TypecheckedUnisonFile Symbol Ann
typecheckedFile) of
    Maybe (Id, EffectDeclaration Symbol Ann)
Nothing -> [Char] -> Id
forall a. HasCallStack => [Char] -> a
error ([Char] -> Id) -> [Char] -> Id
forall a b. (a -> b) -> a -> b
$ [Char]
"No builtin ability called: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
s
    Just (Id
r, EffectDeclaration Symbol Ann
_) -> Id
r

eitherReference,
  optionReference,
  isTestReference,
  isPropagatedReference ::
    R.Reference
eitherReference :: Reference
eitherReference = [Char] -> Reference
typeNamed [Char]
"Either"
optionReference :: Reference
optionReference = [Char] -> Reference
typeNamed [Char]
"Optional"
isTestReference :: Reference
isTestReference = [Char] -> Reference
typeNamed [Char]
"IsTest"
isPropagatedReference :: Reference
isPropagatedReference = [Char] -> Reference
typeNamed [Char]
"IsPropagated"

isTest :: (R.Reference, R.Reference)
isTest :: (Reference, Reference)
isTest = (Reference
isTestReference, [Char] -> Reference
termNamed [Char]
"metadata.isTest")

isIOTest :: (R.Reference, R.Reference)
isIOTest :: (Reference, Reference)
isIOTest = (Reference
isTestReference, [Char] -> Reference
termNamed [Char]
"metadata.isIOTest")

isPropagatedValue :: R.Reference
isPropagatedValue :: Reference
isPropagatedValue = [Char] -> Reference
termNamed [Char]
"metadata.isPropagated"

eitherLeftId, eitherRightId, someId, noneId :: DD.ConstructorId
eitherLeftId :: ConstructorId
eitherLeftId = Reference -> Text -> ConstructorId
constructorNamed Reference
eitherReference Text
"Either.Left"
eitherRightId :: ConstructorId
eitherRightId = Reference -> Text -> ConstructorId
constructorNamed Reference
eitherReference Text
"Either.Right"
someId :: ConstructorId
someId = Reference -> Text -> ConstructorId
constructorNamed Reference
optionReference Text
"Optional.Some"
noneId :: ConstructorId
noneId = Reference -> Text -> ConstructorId
constructorNamed Reference
optionReference Text
"Optional.None"

authorRef, guidRef, copyrightHolderRef :: R.Reference
authorRef :: Reference
authorRef = [Char] -> Reference
typeNamed [Char]
"Author"
guidRef :: Reference
guidRef = [Char] -> Reference
typeNamed [Char]
"GUID"
copyrightHolderRef :: Reference
copyrightHolderRef = [Char] -> Reference
typeNamed [Char]
"CopyrightHolder"

doc2Ref :: R.Reference
doc2Ref :: Reference
doc2Ref = [Char] -> Reference
typeNamed [Char]
"Doc2"

doc2SpecialFormRef :: Reference
doc2SpecialFormRef = [Char] -> Reference
typeNamed [Char]
"Doc2.SpecialForm"

doc2TermRef :: Reference
doc2TermRef = [Char] -> Reference
typeNamed [Char]
"Doc2.Term"

prettyRef :: Reference
prettyRef = [Char] -> Reference
typeNamed [Char]
"Pretty"

prettyAnnotatedRef :: Reference
prettyAnnotatedRef = [Char] -> Reference
typeNamed [Char]
"Pretty.Annotated"

ansiColorRef :: Reference
ansiColorRef = [Char] -> Reference
typeNamed [Char]
"ANSI.Color"

consoleTextRef :: Reference
consoleTextRef = [Char] -> Reference
typeNamed [Char]
"ConsoleText"

pattern $mDoc2Ref :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2Ref <- ((== doc2Ref) -> True)

doc2WordId :: ConstructorId
doc2WordId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Word"

doc2CodeId :: ConstructorId
doc2CodeId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Code"

doc2CodeBlockId :: ConstructorId
doc2CodeBlockId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.CodeBlock"

doc2BoldId :: ConstructorId
doc2BoldId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Bold"

doc2ItalicId :: ConstructorId
doc2ItalicId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Italic"

doc2StrikethroughId :: ConstructorId
doc2StrikethroughId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Strikethrough"

doc2StyleId :: ConstructorId
doc2StyleId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Style"

doc2AnchorId :: ConstructorId
doc2AnchorId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Anchor"

doc2BlockquoteId :: ConstructorId
doc2BlockquoteId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Blockquote"

doc2BlanklineId :: ConstructorId
doc2BlanklineId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Blankline"

doc2LinebreakId :: ConstructorId
doc2LinebreakId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Linebreak"

doc2SectionBreakId :: ConstructorId
doc2SectionBreakId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.SectionBreak"

doc2TooltipId :: ConstructorId
doc2TooltipId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Tooltip"

doc2AsideId :: ConstructorId
doc2AsideId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Aside"

doc2CalloutId :: ConstructorId
doc2CalloutId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Callout"

doc2TableId :: ConstructorId
doc2TableId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Table"

doc2FoldedId :: ConstructorId
doc2FoldedId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Folded"

doc2ParagraphId :: ConstructorId
doc2ParagraphId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Paragraph"

doc2BulletedListId :: ConstructorId
doc2BulletedListId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.BulletedList"

doc2NumberedListId :: ConstructorId
doc2NumberedListId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.NumberedList"

doc2SectionId :: ConstructorId
doc2SectionId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Section"

doc2NamedLinkId :: ConstructorId
doc2NamedLinkId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.NamedLink"

doc2ImageId :: ConstructorId
doc2ImageId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Image"

doc2SpecialId :: ConstructorId
doc2SpecialId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Special"

doc2JoinId :: ConstructorId
doc2JoinId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Join"

doc2UntitledSectionId :: ConstructorId
doc2UntitledSectionId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.UntitledSection"

doc2ColumnId :: ConstructorId
doc2ColumnId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Column"

doc2GroupId :: ConstructorId
doc2GroupId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2Ref Text
"Doc2.Group"

doc2MediaSourceRef :: R.Reference
doc2MediaSourceRef :: Reference
doc2MediaSourceRef = [Char] -> Reference
typeNamed [Char]
"Doc2.MediaSource"

pattern $mDoc2MediaSourceRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2MediaSourceRef <- ((== doc2MediaSourceRef) -> True)

doc2VideoRef :: R.Reference
doc2VideoRef :: Reference
doc2VideoRef = [Char] -> Reference
typeNamed [Char]
"Doc2.Video"

pattern $mDoc2VideoRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2VideoRef <- ((== doc2VideoRef) -> True)

doc2FrontMatterRef :: R.Reference
doc2FrontMatterRef :: Reference
doc2FrontMatterRef = [Char] -> Reference
typeNamed [Char]
"Doc2.FrontMatter"

pattern $mDoc2FrontMatterRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2FrontMatterRef <- ((== doc2FrontMatterRef) -> True)

doc2LaTeXInlineRef :: R.Reference
doc2LaTeXInlineRef :: Reference
doc2LaTeXInlineRef = [Char] -> Reference
typeNamed [Char]
"Doc2.LaTeXInline"

pattern $mDoc2LaTeXInlineRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2LaTeXInlineRef <- ((== doc2LaTeXInlineRef) -> True)

doc2SvgRef :: R.Reference
doc2SvgRef :: Reference
doc2SvgRef = [Char] -> Reference
typeNamed [Char]
"Doc2.Svg"

pattern $mDoc2SvgRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2SvgRef <- ((== doc2SvgRef) -> True)

pattern $mDoc2Word :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Text -> r) -> ((# #) -> r) -> r
Doc2Word txt <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2WordId -> True))) (Term.Text' txt)

pattern $mDoc2Code :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Code d <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2CodeId -> True))) d

pattern $mDoc2CodeBlock :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Text -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2CodeBlock lang d <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2CodeBlockId -> True))) [Term.Text' lang, d]

pattern $mDoc2Bold :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Bold d <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2BoldId -> True))) d

pattern $mDoc2Italic :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Italic d <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2ItalicId -> True))) d

pattern $mDoc2Strikethrough :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Strikethrough d <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2StrikethroughId -> True))) d

pattern $mDoc2Style :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Text -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2Style s d <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2StyleId -> True))) [Term.Text' s, d]

pattern $mDoc2Anchor :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Text -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2Anchor id d <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2AnchorId -> True))) [Term.Text' id, d]

pattern $mDoc2Blockquote :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Blockquote d <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2BlockquoteId -> True))) d

pattern $mDoc2Blankline :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
Doc2Blankline <- Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2BlanklineId -> True))

pattern $mDoc2Linebreak :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
Doc2Linebreak <- Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2LinebreakId -> True))

pattern $mDoc2SectionBreak :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
Doc2SectionBreak <- Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2SectionBreakId -> True))

pattern $mDoc2Tooltip :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2Tooltip d tip <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2TooltipId -> True))) [d, tip]

pattern $mDoc2Aside :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Aside d <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2AsideId -> True))) d

pattern $mDoc2Callout :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2Callout icon d <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2CalloutId -> True))) [icon, d]

pattern $mDoc2Table :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2Table ds <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2TableId -> True))) (Term.List' (toList -> ds))

pattern $mDoc2Folded :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Bool
    -> Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> r)
-> ((# #) -> r)
-> r
Doc2Folded isFolded d d2 <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2FoldedId -> True))) [Term.Boolean' isFolded, d, d2]

pattern $mDoc2Paragraph :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2Paragraph ds <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2ParagraphId -> True))) (Term.List' (toList -> ds))

pattern $mDoc2BulletedList :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2BulletedList ds <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2BulletedListId -> True))) (Term.List' (toList -> ds))

pattern $mDoc2NumberedList :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (ConstructorId -> [Term2 typeVar typeAnn patternAnn v a] -> r)
-> ((# #) -> r)
-> r
Doc2NumberedList n ds <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2NumberedListId -> True))) [Term.Nat' n, Term.List' (toList -> ds)]

pattern $mDoc2Section :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> [Term2 typeVar typeAnn patternAnn v a] -> r)
-> ((# #) -> r)
-> r
Doc2Section title ds <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2SectionId -> True))) [title, Term.List' (toList -> ds)]

pattern $mDoc2NamedLink :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2NamedLink name dest <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2NamedLinkId -> True))) [name, dest]

pattern $mDoc2Image :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> r)
-> ((# #) -> r)
-> r
Doc2Image alt link caption <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2ImageId -> True))) [alt, link, caption]

pattern $mDoc2Special :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Special sf <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2SpecialId -> True))) sf

pattern $mDoc2Join :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2Join ds <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2JoinId -> True))) (Term.List' (toList -> ds))

pattern $mDoc2UntitledSection :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2UntitledSection ds <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2UntitledSectionId -> True))) (Term.List' (toList -> ds))

pattern $mDoc2Column :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2Column ds <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2ColumnId -> True))) (Term.List' (toList -> ds))

pattern $mDoc2Group :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Group d <- Term.App' (Term.Constructor' (ConstructorReference Doc2Ref ((==) doc2GroupId -> True))) d

pattern $mDoc2SpecialFormRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2SpecialFormRef <- ((== doc2SpecialFormRef) -> True)

doc2SpecialFormSourceId :: ConstructorId
doc2SpecialFormSourceId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.Source"

doc2SpecialFormFoldedSourceId :: ConstructorId
doc2SpecialFormFoldedSourceId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.FoldedSource"

doc2SpecialFormExampleId :: ConstructorId
doc2SpecialFormExampleId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.Example"

doc2SpecialFormExampleBlockId :: ConstructorId
doc2SpecialFormExampleBlockId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.ExampleBlock"

doc2SpecialFormLinkId :: ConstructorId
doc2SpecialFormLinkId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.Link"

doc2SpecialFormSignatureId :: ConstructorId
doc2SpecialFormSignatureId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.Signature"

doc2SpecialFormSignatureInlineId :: ConstructorId
doc2SpecialFormSignatureInlineId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.SignatureInline"

doc2SpecialFormEvalId :: ConstructorId
doc2SpecialFormEvalId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.Eval"

doc2SpecialFormEvalInlineId :: ConstructorId
doc2SpecialFormEvalInlineId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.EvalInline"

doc2SpecialFormEmbedId :: ConstructorId
doc2SpecialFormEmbedId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.Embed"

doc2SpecialFormEmbedInlineId :: ConstructorId
doc2SpecialFormEmbedInlineId = Reference -> Text -> ConstructorId
constructorNamed Reference
doc2SpecialFormRef Text
"Doc2.SpecialForm.EmbedInline"

pattern $mDoc2SpecialFormSource :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormSource tm <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormSourceId -> True))) tm

pattern $mDoc2SpecialFormFoldedSource :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormFoldedSource tm <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormFoldedSourceId -> True))) tm

pattern $mDoc2SpecialFormExample :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (ConstructorId -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormExample n tm <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormExampleId -> True))) [Term.Nat' n, tm]

pattern $mDoc2SpecialFormExampleBlock :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (ConstructorId -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormExampleBlock n tm <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormExampleBlockId -> True))) [Term.Nat' n, tm]

pattern $mDoc2SpecialFormLink :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormLink tm <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormLinkId -> True))) tm

pattern $mDoc2SpecialFormSignature :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormSignature tm <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormSignatureId -> True))) tm

pattern $mDoc2SpecialFormSignatureInline :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormSignatureInline tm <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormSignatureInlineId -> True))) tm

pattern $mDoc2SpecialFormEval :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormEval tm <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormEvalId -> True))) tm

pattern $mDoc2SpecialFormEvalInline :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormEvalInline tm <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormEvalInlineId -> True))) tm

pattern $mDoc2SpecialFormEmbed :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormEmbed any <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormEmbedId -> True))) any

pattern $mDoc2SpecialFormEmbedInline :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormEmbedInline any <- Term.App' (Term.Constructor' (ConstructorReference Doc2SpecialFormRef ((==) doc2SpecialFormEmbedInlineId -> True))) any

pattern $mDoc2MediaSource :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
Doc2MediaSource src mimeType <- Term.Apps' (Term.Constructor' (ConstructorReference Doc2MediaSourceRef _)) [src, mimeType]

pattern $mDoc2SpecialFormEmbedVideo :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a]
    -> [Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormEmbedVideo sources config <- Doc2SpecialFormEmbed (Term.App' _ (Term.Apps' (Term.Constructor' (ConstructorReference Doc2VideoRef _)) [Term.List' (toList -> sources), Term.List' (toList -> config)]))

pattern $mDoc2SpecialFormEmbedFrontMatter :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ([Term (F typeVar typeAnn patternAnn) v a] -> r)
-> ((# #) -> r)
-> r
Doc2SpecialFormEmbedFrontMatter frontMatter <- Doc2SpecialFormEmbed (Term.App' _ (Term.App' (Term.Constructor' (ConstructorReference Doc2FrontMatterRef _)) (Term.List' (toList -> frontMatter))))

pattern $mDoc2SpecialFormEmbedLaTeXInline :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Text -> r) -> ((# #) -> r) -> r
Doc2SpecialFormEmbedLaTeXInline latex <- Doc2SpecialFormEmbedInline (Term.App' _ (Term.App' (Term.Constructor' (ConstructorReference Doc2LaTeXInlineRef _)) (Term.Text' latex)))

pattern $mDoc2SpecialFormEmbedSvg :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Text -> r) -> ((# #) -> r) -> r
Doc2SpecialFormEmbedSvg svg <- Doc2SpecialFormEmbed (Term.App' _ (Term.App' (Term.Constructor' (ConstructorReference Doc2SvgRef _)) (Term.Text' svg)))

-- pulls out `vs body` in `Doc2.Term (Any '(vs -> body))`, where
-- vs can be any number of parameters
pattern $mDoc2Example :: forall {r} {vt} {at} {ap} {v} {a}.
Term (F vt at ap) v a
-> ([v] -> Term (F vt at ap) v a -> r) -> ((# #) -> r) -> r
Doc2Example vs body <- Term.App' _term (Term.App' _any (Term.LamNamed' _ (Term.LamsNamedOpt' vs body)))

-- pulls out `body` in `Doc2.Term (Any 'body)`
pattern $mDoc2Term :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
Doc2Term body <- Term.App' _term (Term.App' _any (Term.LamNamed' _ body))

pattern $mDoc2TermRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
Doc2TermRef <- ((== doc2TermRef) -> True)

pattern $mPrettyAnnotatedRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
PrettyAnnotatedRef <- ((== prettyAnnotatedRef) -> True)

prettyEmptyId :: ConstructorId
prettyEmptyId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.Empty"

prettyGroupId :: ConstructorId
prettyGroupId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.Group"

prettyLitId :: ConstructorId
prettyLitId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.Lit"

prettyWrapId :: ConstructorId
prettyWrapId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.Wrap"

prettyOrElseId :: ConstructorId
prettyOrElseId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.OrElse"

prettyIndentId :: ConstructorId
prettyIndentId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.Indent"

prettyAppendId :: ConstructorId
prettyAppendId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.Append"

prettyTableId :: ConstructorId
prettyTableId = Reference -> Text -> ConstructorId
constructorNamed Reference
prettyAnnotatedRef Text
"Pretty.Annotated.Table"

pattern $mPrettyEmpty :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
PrettyEmpty <- Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyEmptyId -> True))

pattern $mPrettyGroup :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
PrettyGroup ann tm <- Term.Apps' (Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyGroupId -> True))) [ann, tm]

pattern $mPrettyLit :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
PrettyLit ann tm <- Term.Apps' (Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyLitId -> True))) [ann, tm]

pattern $mPrettyWrap :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
PrettyWrap ann tm <- Term.Apps' (Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyWrapId -> True))) [ann, tm]

pattern $mPrettyIndent :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> r)
-> ((# #) -> r)
-> r
PrettyIndent ann i0 i1 tm <- Term.Apps' (Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyIndentId -> True))) [ann, i0, i1, tm]

pattern $mPrettyOrElse :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a
    -> r)
-> ((# #) -> r)
-> r
PrettyOrElse ann p1 p2 <- Term.Apps' (Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyOrElseId -> True))) [ann, p1, p2]

pattern $mPrettyTable :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Seq (Term2 typeVar typeAnn patternAnn v a) -> r)
-> ((# #) -> r)
-> r
PrettyTable ann rows <- Term.Apps' (Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyTableId -> True))) [ann, Term.List' rows]

pattern $mPrettyAppend :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Seq (Term2 typeVar typeAnn patternAnn v a) -> r)
-> ((# #) -> r)
-> r
PrettyAppend ann tms <- Term.Apps' (Term.Constructor' (ConstructorReference PrettyAnnotatedRef ((==) prettyAppendId -> True))) [ann, Term.List' tms]

pattern $mPrettyRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
PrettyRef <- ((== prettyRef) -> True)

prettyGetRef :: Reference
prettyGetRef = [Char] -> Reference
termNamed [Char]
"Pretty.get"

doc2FormatConsoleRef :: Reference
doc2FormatConsoleRef = [Char] -> Reference
termNamed [Char]
"syntax.docFormatConsole"

pattern $mAnsiColorRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorRef <- ((== ansiColorRef) -> True)

( ConstructorId
ansiColorBlackId,
  ConstructorId
ansiColorRedId,
  ConstructorId
ansiColorGreenId,
  ConstructorId
ansiColorYellowId,
  ConstructorId
ansiColorBlueId,
  ConstructorId
ansiColorMagentaId,
  ConstructorId
ansiColorCyanId,
  ConstructorId
ansiColorWhiteId,
  ConstructorId
ansiColorBrightBlackId,
  ConstructorId
ansiColorBrightRedId,
  ConstructorId
ansiColorBrightGreenId,
  ConstructorId
ansiColorBrightYellowId,
  ConstructorId
ansiColorBrightBlueId,
  ConstructorId
ansiColorBrightMagentaId,
  ConstructorId
ansiColorBrightCyanId,
  ConstructorId
ansiColorBrightWhiteId
  ) =
    ( Text -> ConstructorId
ct Text
"Black",
      Text -> ConstructorId
ct Text
"Red",
      Text -> ConstructorId
ct Text
"Green",
      Text -> ConstructorId
ct Text
"Yellow",
      Text -> ConstructorId
ct Text
"Blue",
      Text -> ConstructorId
ct Text
"Magenta",
      Text -> ConstructorId
ct Text
"Cyan",
      Text -> ConstructorId
ct Text
"White",
      Text -> ConstructorId
ct Text
"BrightBlack",
      Text -> ConstructorId
ct Text
"BrightRed",
      Text -> ConstructorId
ct Text
"BrightGreen",
      Text -> ConstructorId
ct Text
"BrightYellow",
      Text -> ConstructorId
ct Text
"BrightBlue",
      Text -> ConstructorId
ct Text
"BrightMagenta",
      Text -> ConstructorId
ct Text
"BrightCyan",
      Text -> ConstructorId
ct Text
"BrightWhite"
    )
    where
      ct :: Text -> DD.ConstructorId
      ct :: Text -> ConstructorId
ct Text
n = Reference -> Text -> ConstructorId
constructorNamed Reference
ansiColorRef (Text
"ANSI.Color." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
n)

pattern $mAnsiColorBlack :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBlack <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBlackId -> True))

pattern $mAnsiColorRed :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorRed <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorRedId -> True))

pattern $mAnsiColorGreen :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorGreen <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorGreenId -> True))

pattern $mAnsiColorYellow :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorYellow <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorYellowId -> True))

pattern $mAnsiColorBlue :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBlue <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBlueId -> True))

pattern $mAnsiColorMagenta :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorMagenta <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorMagentaId -> True))

pattern $mAnsiColorCyan :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorCyan <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorCyanId -> True))

pattern $mAnsiColorWhite :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorWhite <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorWhiteId -> True))

pattern $mAnsiColorBrightBlack :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightBlack <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightBlackId -> True))

pattern $mAnsiColorBrightRed :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightRed <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightRedId -> True))

pattern $mAnsiColorBrightGreen :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightGreen <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightGreenId -> True))

pattern $mAnsiColorBrightYellow :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightYellow <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightYellowId -> True))

pattern $mAnsiColorBrightBlue :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightBlue <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightBlueId -> True))

pattern $mAnsiColorBrightMagenta :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightMagenta <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightMagentaId -> True))

pattern $mAnsiColorBrightCyan :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightCyan <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightCyanId -> True))

pattern $mAnsiColorBrightWhite :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> ((# #) -> r) -> ((# #) -> r) -> r
AnsiColorBrightWhite <- Term.Constructor' (ConstructorReference AnsiColorRef ((==) ansiColorBrightWhiteId -> True))

pattern $mConsoleTextRef :: forall {r}. Reference -> ((# #) -> r) -> ((# #) -> r) -> r
ConsoleTextRef <- ((== consoleTextRef) -> True)

consoleTextPlainId :: ConstructorId
consoleTextPlainId = Reference -> Text -> ConstructorId
constructorNamed Reference
consoleTextRef Text
"ConsoleText.Plain"

consoleTextForegroundId :: ConstructorId
consoleTextForegroundId = Reference -> Text -> ConstructorId
constructorNamed Reference
consoleTextRef Text
"ConsoleText.Foreground"

consoleTextBackgroundId :: ConstructorId
consoleTextBackgroundId = Reference -> Text -> ConstructorId
constructorNamed Reference
consoleTextRef Text
"ConsoleText.Background"

consoleTextBoldId :: ConstructorId
consoleTextBoldId = Reference -> Text -> ConstructorId
constructorNamed Reference
consoleTextRef Text
"ConsoleText.Bold"

consoleTextUnderlineId :: ConstructorId
consoleTextUnderlineId = Reference -> Text -> ConstructorId
constructorNamed Reference
consoleTextRef Text
"ConsoleText.Underline"

consoleTextInvertId :: ConstructorId
consoleTextInvertId = Reference -> Text -> ConstructorId
constructorNamed Reference
consoleTextRef Text
"ConsoleText.Invert"

pattern $mConsoleTextPlain :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
ConsoleTextPlain txt <- Term.App' (Term.Constructor' (ConstructorReference ConsoleTextRef ((==) consoleTextPlainId -> True))) txt

pattern $mConsoleTextForeground :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
ConsoleTextForeground color ct <- Term.Apps' (Term.Constructor' (ConstructorReference ConsoleTextRef ((==) consoleTextForegroundId -> True))) [color, ct]

pattern $mConsoleTextBackground :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term2 typeVar typeAnn patternAnn v a
-> (Term2 typeVar typeAnn patternAnn v a
    -> Term2 typeVar typeAnn patternAnn v a -> r)
-> ((# #) -> r)
-> r
ConsoleTextBackground color ct <- Term.Apps' (Term.Constructor' (ConstructorReference ConsoleTextRef ((==) consoleTextBackgroundId -> True))) [color, ct]

pattern $mConsoleTextBold :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
ConsoleTextBold ct <- Term.App' (Term.Constructor' (ConstructorReference ConsoleTextRef ((==) consoleTextBoldId -> True))) ct

pattern $mConsoleTextUnderline :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
ConsoleTextUnderline ct <- Term.App' (Term.Constructor' (ConstructorReference ConsoleTextRef ((==) consoleTextUnderlineId -> True))) ct

pattern $mConsoleTextInvert :: forall {r} {typeVar} {typeAnn} {patternAnn} {v} {a}.
Term (F typeVar typeAnn patternAnn) v a
-> (Term (F typeVar typeAnn patternAnn) v a -> r)
-> ((# #) -> r)
-> r
ConsoleTextInvert ct <- Term.App' (Term.Constructor' (ConstructorReference ConsoleTextRef ((==) consoleTextInvertId -> True))) ct

iarrayFromListRef :: R.Reference
iarrayFromListRef :: Reference
iarrayFromListRef = [Char] -> Reference
termNamed [Char]
"ImmutableArray.fromList"

ibarrayFromBytesRef :: R.Reference
ibarrayFromBytesRef :: Reference
ibarrayFromBytesRef = [Char] -> Reference
termNamed [Char]
"ImmutableByteArray.fromBytes"

constructorNamed :: R.Reference -> Text -> DD.ConstructorId
constructorNamed :: Reference -> Text -> ConstructorId
constructorNamed Reference
ref Text
name =
  case Identity (Maybe (Decl Symbol Ann)) -> Maybe (Decl Symbol Ann)
forall a. Identity a -> a
runIdentity (Identity (Maybe (Decl Symbol Ann)) -> Maybe (Decl Symbol Ann))
-> (Id -> Identity (Maybe (Decl Symbol Ann)))
-> Id
-> Maybe (Decl Symbol Ann)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeLookup Symbol Identity Ann
-> Id -> Identity (Maybe (Decl Symbol Ann))
forall v (m :: * -> *) a.
CodeLookup v m a -> Id -> m (Maybe (Decl v a))
getTypeDeclaration CodeLookup Symbol Identity Ann
codeLookup (Id -> Maybe (Decl Symbol Ann)) -> Id -> Maybe (Decl Symbol Ann)
forall a b. (a -> b) -> a -> b
$ Reference -> Id
R.unsafeId Reference
ref of
    Maybe (Decl Symbol Ann)
Nothing ->
      [Char] -> ConstructorId
forall a. HasCallStack => [Char] -> a
error ([Char] -> ConstructorId) -> [Char] -> ConstructorId
forall a b. (a -> b) -> a -> b
$
        [Char]
"There's a bug in the Unison runtime. Couldn't find type "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Reference -> [Char]
forall a. Show a => a -> [Char]
show Reference
ref
    Just Decl Symbol Ann
decl ->
      Int -> ConstructorId
forall a b. (Integral a, Num b) => a -> b
fromIntegral
        (Int -> ConstructorId)
-> (DataDeclaration Symbol Ann -> Int)
-> DataDeclaration Symbol Ann
-> ConstructorId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe
          ( [Char] -> Int
forall a. HasCallStack => [Char] -> a
error ([Char] -> Int) -> [Char] -> Int
forall a b. (a -> b) -> a -> b
$
              [Char]
"Unison runtime bug. The type "
                [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Reference -> [Char]
forall a. Show a => a -> [Char]
show Reference
ref
                [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
" has no constructor named "
                [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Text -> [Char]
forall a. Show a => a -> [Char]
show Text
name
          )
        (Maybe Int -> Int)
-> (DataDeclaration Symbol Ann -> Maybe Int)
-> DataDeclaration Symbol Ann
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex Text
name
        ([Text] -> Maybe Int)
-> (DataDeclaration Symbol Ann -> [Text])
-> DataDeclaration Symbol Ann
-> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration Symbol Ann -> [Text]
forall v a. Var v => DataDeclaration v a -> [Text]
DD.constructorNames
        (DataDeclaration Symbol Ann -> ConstructorId)
-> DataDeclaration Symbol Ann -> ConstructorId
forall a b. (a -> b) -> a -> b
$ Decl Symbol Ann -> DataDeclaration Symbol Ann
forall v a. Decl v a -> DataDeclaration v a
DD.asDataDecl Decl Symbol Ann
decl

constructorName :: R.Reference -> DD.ConstructorId -> Text
constructorName :: Reference -> ConstructorId -> Text
constructorName Reference
ref ConstructorId
cid =
  case Identity (Maybe (Decl Symbol Ann)) -> Maybe (Decl Symbol Ann)
forall a. Identity a -> a
runIdentity (Identity (Maybe (Decl Symbol Ann)) -> Maybe (Decl Symbol Ann))
-> (Id -> Identity (Maybe (Decl Symbol Ann)))
-> Id
-> Maybe (Decl Symbol Ann)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeLookup Symbol Identity Ann
-> Id -> Identity (Maybe (Decl Symbol Ann))
forall v (m :: * -> *) a.
CodeLookup v m a -> Id -> m (Maybe (Decl v a))
getTypeDeclaration CodeLookup Symbol Identity Ann
codeLookup (Id -> Maybe (Decl Symbol Ann)) -> Id -> Maybe (Decl Symbol Ann)
forall a b. (a -> b) -> a -> b
$ Reference -> Id
R.unsafeId Reference
ref of
    Maybe (Decl Symbol Ann)
Nothing ->
      [Char] -> Text
forall a. HasCallStack => [Char] -> a
error ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$
        [Char]
"There's a bug in the Unison runtime. Couldn't find type "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Reference -> [Char]
forall a. Show a => a -> [Char]
show Reference
ref
    Just Decl Symbol Ann
decl -> [Text] -> ConstructorId -> Text
forall i a. Integral i => [a] -> i -> a
genericIndex (DataDeclaration Symbol Ann -> [Text]
forall v a. Var v => DataDeclaration v a -> [Text]
DD.constructorNames (DataDeclaration Symbol Ann -> [Text])
-> DataDeclaration Symbol Ann -> [Text]
forall a b. (a -> b) -> a -> b
$ Decl Symbol Ann -> DataDeclaration Symbol Ann
forall v a. Decl v a -> DataDeclaration v a
DD.asDataDecl Decl Symbol Ann
decl) ConstructorId
cid

-- .. todo - fill in the rest of these

sourceString :: String
sourceString :: [Char]
sourceString =
  Text -> [Char]
Text.unpack Text
source

source :: Text
source :: Text
source =
  [Char] -> Text
forall a. IsString a => [Char] -> a
fromString
    [Char]
[r|

structural type Either a b = Left a | Right b

structural type Optional a = None | Some a

unique[b28d929d0a73d2c18eac86341a3bb9399f8550c11b5f35eabb2751e6803ccc20] type
  IsPropagated = IsPropagated

d1 Doc.++ d2 =
  use Doc2
  match (d1,d2) with
    (Join ds, Join ds2) -> Join (ds List.++ ds2)
    (Join ds, _) -> Join (List.snoc ds d2)
    (_, Join ds) -> Join (List.cons d1 ds)
    _ -> Join [d1,d2]

unique[q1905679b27a97a4098bc965574da880c1074183a2c55ff1d481619c7fb8a1e1] type
  Author = { guid : GUID, name : Text }

unique[ee1c051034fa0671ea66e7c708ba552003bd3cf657bd28bf0051f1f8cdfcba53] type
  CopyrightHolder = { guid : GUID, name : Text}

unique[bed6724af0d5f47f80cdea1b6023d35f120137ee0556e57154a9fc8b62fe5fed] type
  License = { copyrightHolders : [CopyrightHolder]
            , years : [Year]
            , licenseType : LicenseType }

-- Use `Doc` here to get nice text-wrapping when viewing
-- and to avoid needing to stick hard line breaks in the license
unique[d875fa1ea7ef3adf8e29417c6c8b01a1830c4c6bd10dcca9d4196388462e0b7a] type LicenseType = LicenseType Doc

unique[cb8469a1b41a63655062226556eaccf06129a2641af61fe7edef9c485c94a870] type GUID = GUID Bytes

-- Common era years
unique[u9ae6694152966cf1b0c1f4ad901a77e1acd7bbe16595fd27b07435ac45dab05] type Year = Year Nat

-- This is linked to definitions that are considered tests
unique[e6dca08b40458b03ca1660cfbdaecaa7279b42d18257898b5fd1c34596aac36f] type
  IsTest = IsTest

-- Create references for these that can be used as metadata.
-- (Reminder: Metadata is references, not values.)
metadata.isTest = IsTest.IsTest
metadata.isPropagated = IsPropagated.IsPropagated

-- Built-ins

-- A newtype used when embedding term references in a Doc2
unique[fb488e55e66e2492c2946388e4e846450701db04] type Doc2.Term = Term Any

-- Media types for Doc2.Embed.
-- Somewhat modelled after:
--   https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source and
--   https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video

unique[ab9344724264495159ec7122d276a6358630403b6a5529e1e5d76bcf] type Doc2.MediaSource
  = { sourceUrl: Text, mimeType: Optional Text }

-- Used with MediaSource to embed videos in a Doc. The `config` field is
-- intended to be used to add attributes etc, like `poster` or `autoplay` for
-- the HTML <video> element, if rendered as such.
unique[b2ada5dfd4112ca3a7ba0a6483ce3d82811400c56eff8e6eca1b3fbf] type Doc2.Video
  = { sources: [Doc2.MediaSource]
    , config: [(Text, Text)]
    }

-- Useful for embedded data into a Doc, like title, date, tags etc:
unique[ea60b6205a6b25449a8784de87c113833bacbcdfe32829c7a76985d5] type Doc2.FrontMatter
  = FrontMatter [(Text, Text)]

-- Similar to using triple backticks with a latex pragma (```latex), but for
-- when you'd want to render LaTeX inline
unique[d1dc0515a2379df8a4c91571fe2f9bf9322adaf97677c87b806e49572447c688] type Doc2.LaTeXInline
  = LaTeXInline Text

-- Used for embedding SVGs
unique[ae4e05d8bede04825145db1a6a2222fdf2d890b3044d86fd4368f53b265de7f9] type Doc2.Svg
  = Svg Text

-- ex: Doc2.term 'List.map
Doc2.term : ∀ a g1 g. '{g} a ->{g1} Doc2.Term
Doc2.term a = Doc2.Term.Term (Any a)

unique[da70bff6431da17fa515f3d18ded11852b6a745f] type Doc2.SpecialForm
  -- @source{type Optional, List.map @ note1 note2} OR
  -- The notes are ignored currently, but will later be used to produce
  -- rich annotated source code with tooltips, highlights and whatnot.
  = Source [(Either Link.Type Doc2.Term, [Doc2.Term])]
  -- like Source, but the code starts out folded
  | FoldedSource [(Either Link.Type Doc2.Term, [Doc2.Term])]
  -- In `Example n expr`, `n` is the number of lambda parameters
  -- that should be elided during display.
  -- Ex: `Example 2 '(x y -> foo x y)` should render as `foo x y`.
  -- Ex: `Example 0 '(1 + 1)` should render as `42`.
  | Example Nat Doc2.Term
  -- Same as `Example`, but as a block rather than inline element
  | ExampleBlock Nat Doc2.Term
  -- {type Optional} or {List.map}
  | Link (Either Link.Type Doc2.Term)
  -- @signatures{List.map, List.filter, List.foldLeft}
  | Signature [Doc2.Term]
  -- @signature{List.map}
  | SignatureInline Doc2.Term
  -- ```
  -- id x = x
  -- id 42 + 1
  -- ```
  | Eval Doc2.Term
  -- @eval{1 + 1}
  | EvalInline Doc2.Term
  -- For extensions like a `Diagram` or `Animation` type.
  -- Renderers will be best effort for these; not all
  -- renderers will support all extensions
  | Embed Any
  | EmbedInline Any

unique[b7a4fb87e34569319591130bf3ec6e24c9955b6a] type Doc2
  -- Just raw text embedded in a doc. Will be unbroken.
  = Word Text
  -- Inline monospace, as in ''some monospace code''.
  | Code Doc2
  -- Block monospace with syntax highlighting.
  -- ''' blocks are parsed as ``` raw
  | CodeBlock Text Doc2
  | Bold Doc2
  | Italic Doc2
  | Strikethrough Doc2
  -- Can be used to affect HTML rendering
  | Style Text Doc2
  -- Create a named anchor point which can be used in links
  -- as in HTML: <h2><a id="section1">Section 1 Title</a></h2>
  | Anchor Text Doc2
  | Blockquote Doc2
  | Blankline
  | Linebreak
  -- For longer sections, this inserts a doodad or thingamajig
  | SectionBreak
  -- Tooltip inner tooltipContent
  | Tooltip Doc2 Doc2
  -- Aside asideContent
  | Aside Doc2
  -- Callout icon content
  | Callout (Optional Doc2) Doc2
  -- Table rows
  | Table [[Doc2]]
  -- Folded isFolded summary details
  -- If folded, only summary is shown, otherwise
  -- summary is followed by details. Some renderers
  -- will present this as a toggle or clickable elipses
  | Folded Boolean Doc2 Doc2
  -- Documents separated by spaces and wrapped to available width
  | Paragraph [Doc2]
  | BulletedList [Doc2]
  -- NumberedList startingNumber listElements
  | NumberedList Nat [Doc2]
  -- Section title subelements
  | Section Doc2 [Doc2]
  -- [our website](https://www.unison-lang.org/) or [blah]({type MyType})
  | NamedLink Doc2 Doc2
  -- image alt-text link caption
  | Image Doc2 Doc2 (Optional Doc2)
  | Special Doc2.SpecialForm
  -- Concatenation of docs
  | Join [Doc2]
  -- A section with no title but otherwise laid out the same
  | UntitledSection [Doc2]
  -- A list of documents that should start on separate lines;
  -- this is used for nested lists, for instance
  -- * A
  --   * A.1
  --   * A.2
  -- * B
  --   * B.1
  --   * B.2
  -- Is modeled as:
  --   BulletedList [ Column [A, BulletedList [A.1, A.2]]
  --                , Column [B, BulletedList [B.1, B.2]]
  | Column [Doc2]
  -- Sometimes useful in paragraph text to avoid line breaks in
  -- awkward places
  | Group Doc2

unique[d7b2ced8c08b2c6e54050d1f5acedef3395f293d] type Pretty.Annotated w txt
  -- See more detailed comments below on Pretty smart constructors, like
  -- Pretty.orElse, Pretty.group, etc
  = Empty
  | Group w (Pretty.Annotated w txt)
  | Lit w txt
  | Wrap w (Pretty.Annotated w txt)
  | OrElse w (Pretty.Annotated w txt) (Pretty.Annotated w txt)
  -- table rows
  | Table w [[Pretty.Annotated w txt]]
  -- Indent _ initialIndent indentAfterNewline p prefixes the first
  -- line of `p` with `initialIndent`, and subsequent lines by `indentAfterNewline`.
  | Indent w (Pretty.Annotated w txt) (Pretty.Annotated w txt) (Pretty.Annotated w txt)
  | Append w [Pretty.Annotated w txt]

structural type Pretty txt = Pretty (Pretty.Annotated () txt)

Pretty.get = cases Pretty p -> p

Pretty.map : (txt ->{g} txt2) ->{} Pretty txt ->{g} Pretty txt2
Pretty.map f p =
  use Pretty.Annotated
  go = cases
    Empty -> Empty
    Group _ p -> Group () (go p)
    Lit _ t -> Lit () (f t)
    Wrap _ p -> Wrap () (go p)
    OrElse _ p1 p2 -> OrElse () (go p1) (go p2)
    Table _ xs -> Table () (List.map (List.map go) xs)
    Indent _ i0 iN p -> Indent () (go i0) (go iN) (go p)
    Annotated.Append _ ps -> Annotated.Append () (List.map go ps)
  Pretty (go (Pretty.get p))

Pretty.empty : Pretty txt
Pretty.empty = Pretty Empty

{- A group adds a level of breaking. Layout tries not to break a group
   unless needed to fit in available width. Breaking is done "outside in".

   (a | b) <> (c | d) will try (a <> c)
                          then (b <> d)

   (a | b) <> group (c | d) will try (a <> c)
                                then (b <> c)
                                then (b <> d)
-}
Pretty.group : Pretty txt -> Pretty txt
Pretty.group p = Pretty (Group () (Pretty.get p))

-- Create a leaf-level `Pretty` that cannot be broken.
Pretty.lit : txt -> Pretty txt
Pretty.lit txt = Pretty (Lit () txt)

-- Turn on wrapping for `p`, which means that it inserts
-- softbreaks (either a space or a newline) between each
-- subgroup or leaf.
-- wrap (lit a <> lit b <> group c) ==
-- wrap (lit a <> group (orElse (lit " ") (lit "\n")
Pretty.wrap : Pretty txt -> Pretty txt
Pretty.wrap p = Pretty (Wrap () (Pretty.get p))

-- If `p1` fits on the current line at its preferred width,
-- it will be chosen, otherwise `p2` is chosen.
Pretty.orElse : Pretty txt -> Pretty txt -> Pretty txt
Pretty.orElse p1 p2 = Pretty (OrElse () (Pretty.get p1) (Pretty.get p2))

-- Prefixes all lines of `p` by `by`.
Pretty.indent : Pretty txt -> Pretty txt -> Pretty txt
Pretty.indent by p = Pretty (Indent () (Pretty.get by) (Pretty.get by) (Pretty.get p))

-- Prefixes the first line of `p` with `initialIndent`, and
-- subsequent lines by `indentAfterNewline`.
Pretty.indent' : Pretty txt -> Pretty txt -> Pretty txt -> Pretty txt
Pretty.indent' initialIndent indentAfterNewline p =
  Pretty (Indent () (Pretty.get initialIndent)
                    (Pretty.get indentAfterNewline)
                    (Pretty.get p))

Pretty.table : [[Pretty txt]] -> Pretty txt
Pretty.table rows = Pretty (Annotated.Table () (List.map (List.map Pretty.get) rows))

Pretty.append : Pretty txt -> Pretty txt -> Pretty txt
Pretty.append p1 p2 =
  use Pretty.Annotated Empty Append
  match (Pretty.get p1, Pretty.get p2) with
    (_, Empty) -> p1
    (Empty, _) -> p2
    (Append _ ps1, Append _ ps2) -> Pretty (Append () (ps1 List.++ ps2))
    (Append _ ps1, p2) -> Pretty (Append () (ps1 :+ p2))
    (p1, Append _ ps2) -> Pretty (Append () (p1 +: ps2))
    (p1,p2) -> Pretty (Append () [p1,p2])

Pretty.join : [Pretty txt] -> Pretty txt
Pretty.join =
  go acc = cases [] -> acc
                 h +: t -> go (append acc h) t
  go Pretty.empty

Pretty.sepBy : Pretty txt -> [Pretty txt] -> Pretty txt
Pretty.sepBy sep ps =
  go acc insertSep = cases
    [] -> acc
    ps | insertSep -> go (append acc sep) false ps
    h +: t -> go (append acc h) true t
  go Pretty.empty false ps

syntax.docJoin = cases [d] -> d
                       ds  -> Doc2.Join ds
syntax.docUntitledSection = cases
  [d] -> d
  ds -> UntitledSection ds
syntax.docColumn = cases
  [d] -> d
  ds -> Doc2.Column ds
syntax.docGroup = Doc2.Group
syntax.docWord = Word
syntax.docBold = Doc2.Bold
syntax.docItalic = Italic
syntax.docStrikethrough = Strikethrough
syntax.docParagraph = Paragraph
syntax.docEmbedTermLink tm =
  guid = "9d3927033a9589dda2d10406840af7ef3b4bf21e"
  Right (Doc2.term tm)
syntax.docEmbedTypeLink typ =
  guid = "f9e80035f8c21ac80c98b6c2cc06fe004ae2eb2c"
  Left typ
syntax.docSource t = Special (Source t)
syntax.docFoldedSource t = Special (FoldedSource t)
syntax.docSignature ts = Special (Signature ts)
syntax.docSignatureInline t = Special (SignatureInline t)
syntax.docSourceElement link annotations =
  guid = "e56ece7785c34c1cc9a441b11da81cfa98d05985"
  (link, annotations)
syntax.docEmbedAnnotations tms =
  guid = "11f21dc3bcb37652d8058d655e757560ac38f7b3"
  tms
syntax.docEmbedAnnotation tm =
  guid = "8546106e53c88996c8d3eb785a2fca80df9c7b3b"
  Doc2.Term.Term (Any tm)
syntax.docEmbedSignatureLink tm =
  guid = "d9a4fb87e34569319591130bf3ec6e24"
  Doc2.term tm
syntax.docCode c = Code c
syntax.docCodeBlock typ c = CodeBlock typ (docWord c)
syntax.docVerbatim c = CodeBlock "raw" c
syntax.docEval : '{} a -> Doc2
syntax.docEval d = Special (Eval (Doc2.term d))
syntax.docEvalInline : '{} a -> Doc2
syntax.docEvalInline a = Special (EvalInline (Doc2.term a))
syntax.docExample n a = Special (Example n (Doc2.term a))
syntax.docExampleBlock n a = Special (ExampleBlock n (Doc2.term a))
syntax.docLink t = Special (Link t)
syntax.docTransclude d =
  guid = "b7a4fb87e34569319591130bf3ec6e24"
  d
syntax.docNamedLink = NamedLink
syntax.docBulletedList = BulletedList
syntax.docNumberedList = NumberedList
syntax.docSection = Section
syntax.docTable = Doc2.Table
syntax.docBlockquote = Blockquote
syntax.docCallout = Callout
syntax.docAside = Aside
syntax.docTooltip = Tooltip

unique[e25bc44d251ae0301517ad0bd02cbd294161dc89] type ConsoleText
  = Plain Text
  | Foreground ANSI.Color ConsoleText
  | Background ANSI.Color ConsoleText
  | Bold ConsoleText
  | Underline ConsoleText
  | Invert ConsoleText

unique[de2e0ee924578939213c950dfd8e0ba1047703ae] type ANSI.Color
  = Black | Red | Green | Yellow | Blue | Magenta | Cyan | White
  | BrightBlack | BrightRed | BrightGreen | BrightYellow | BrightBlue
  | BrightMagenta | BrightCyan | BrightWhite

List.map : (a ->{e} b) -> [a] ->{e} [b]
List.map f a =
  go i as acc =
    match List.at i as with
      None   -> acc
      Some a ->
        use Nat +
        go (i + 1) as (acc :+ f a)
  go 0 a []

Text.alignRightWith : Nat -> Char -> Text -> Text
Text.alignRightWith w padChar txt =
  rem = drop w (Text.size txt)
  if rem == 0 then txt
  else Text.repeat rem (Char.toText padChar) Text.++ txt

Text.alignLeftWith : Nat -> Char -> Text -> Text
Text.alignLeftWith w padChar txt =
  rem = drop w (Text.size txt)
  if rem == 0 then txt
  else txt Text.++ Text.repeat rem (Char.toText padChar)

Either.mapRight : (a -> b) -> Either e a -> Either e b
Either.mapRight f = cases
  Left e -> Left e
  Right a -> Right (f a)

syntax.docFormatConsole : Doc2 -> Pretty (Either SpecialForm ConsoleText)
syntax.docFormatConsole d =
  use Doc2
  lit t = Pretty.lit (Right (Plain t))
  p1 <> p2 = Pretty.append p1 p2
  nl = lit "\n"
  map f p = Pretty.map (mapRight f) p
  go = cases
    Word t -> lit t
    Code d -> Pretty.group (lit "`" <> go d <> lit "`")
    CodeBlock typ d -> Pretty.group (
      lit "``` " <> Pretty.group (lit typ) <> nl <>
      go d <> nl <>
      lit "```")
    Italic (Paragraph ([l] ++ mid ++ [r])) ->
      Pretty.group (lit "*" <> go l) <>
      Pretty.join (List.map go mid) <>
      Pretty.group (go r <> lit "*")
    Italic d -> Pretty.group (lit "*" <> go d <> lit "*")
    Strikethrough (Paragraph ([l] ++ mid ++ [r])) ->
      Pretty.group (lit "~~" <> go l) <>
      Pretty.join (List.map go mid) <>
      Pretty.group (go r <> lit "~~")
    Strikethrough d -> Pretty.group (lit "~~" <> go d <> lit "~~")
    Doc2.Bold d -> map ConsoleText.Bold (go d)
    Style _ d -> go d
    Anchor _ d -> go d
    Blockquote d -> Pretty.group (Pretty.indent (lit "> ") (go d))
    Blankline -> Pretty.group (lit "\n\n")
    Linebreak -> Pretty.group (lit "\n")
    SectionBreak -> lit "܍"
    Tooltip inner _ -> go inner
    Aside d -> map (Foreground BrightBlack) (lit "(" <> go d <> lit ")")
    Callout None d -> Pretty.group (Pretty.indent (lit "  | ") (go d))
    Callout (Some icon) d ->
      Pretty.group (Pretty.indent (lit "  | ") (
        Pretty.sepBy nl [
          map ConsoleText.Bold (go icon),
          lit "",
          go d
        ]))
    Table rows -> Pretty.table (List.map (List.map go) rows)
    Folded _ summary details -> go summary <> go details
    Paragraph ds -> Pretty.wrap (Pretty.join (List.map go ds))
    BulletedList ds ->
      item d = Pretty.indent' (lit "* ") (lit "  ") (go d)
      items = List.map item ds
      Pretty.group (Pretty.sepBy nl items)
    NumberedList n ds ->
      dot = ". "
      w = Text.size (Nat.toText (n + List.size ds)) + size dot
      num n = lit (Text.alignRightWith w ?\s (Nat.toText n Text.++ dot))
      indent = lit (Text.repeat w " ")
      item : Nat -> Doc2 -> Pretty (Either SpecialForm ConsoleText)
      item n d = Pretty.indent' (num n) indent (go d)
      items n acc = cases [] -> acc
                          d +: ds -> items (n+1) (acc :+ item n d) ds
      Pretty.group (Pretty.sepBy nl (items n [] ds))
    Section title ds ->
      ggo d = Pretty.group (go d)
      t = Pretty.indent' (lit "# ") (lit "  ") (ggo (Doc2.Bold title))
      subs = List.map (d -> Pretty.indent (lit "  ") (ggo d)) ds
      Pretty.group (Pretty.sepBy (nl <> nl) (t +: subs))
    UntitledSection ds ->
      ggo d = Pretty.group (go d)
      Pretty.group (Pretty.sepBy (nl <> nl) (List.map ggo ds))
    Join ds -> Pretty.join (List.map go ds)
    Column ds -> Pretty.sepBy nl (List.map go ds)
    Group d -> Pretty.group (go d)
    NamedLink name _target -> map ConsoleText.Underline (go name)
    Image alt _link (Some caption) -> Pretty.sepBy nl [go alt, go (Italic caption)]
    Image alt _link None -> go alt
    Special sf -> Pretty.lit (Left sf)
  go d

ImmutableArray.fromList l = Scope.run do
  sz = List.size l
  dst = Scope.array sz
  go i = cases
    [] -> ()
    x +: xs ->
      MutableArray.write dst i x
      go (i+1) xs
  handle go 0 l with cases
    { r } -> ()
    { raise _ -> _ } -> ()
  MutableArray.freeze! dst

ImmutableByteArray.fromBytes : Bytes -> ImmutableByteArray
ImmutableByteArray.fromBytes bs = Scope.run do
  sz = Bytes.size bs
  arr = Scope.bytearray sz
  fill i =
    match Bytes.at i bs with
      Some b ->
        MutableByteArray.write8 arr i b
        fill (i + 1)
      None -> ()
  handle fill 0
  with cases
    { _ }                      -> ()
    { raise _ -> _ } -> ()
  MutableByteArray.freeze! arr
|]

type Note = Result.Note Symbol Ann

type TFile = UF.TypecheckedUnisonFile Symbol Ann

type SynthResult =
  Result.Result
    (Seq Note)
    (Either (UF.UnisonFile Symbol Ann) TFile)

type EitherResult = Either String TFile

showNotes :: (Foldable f) => String -> PrintError.Env -> f Note -> String
showNotes :: forall (f :: * -> *).
Foldable f =>
[Char] -> Env -> f (Note Symbol Ann) -> [Char]
showNotes [Char]
source Env
env =
  [Char]
-> (Note Symbol Ann -> [Char]) -> f (Note Symbol Ann) -> [Char]
forall (t :: * -> *) a b.
(Foldable t, Monoid a) =>
a -> (b -> a) -> t b -> a
intercalateMap [Char]
"\n\n" ((Note Symbol Ann -> [Char]) -> f (Note Symbol Ann) -> [Char])
-> (Note Symbol Ann -> [Char]) -> f (Note Symbol Ann) -> [Char]
forall a b. (a -> b) -> a -> b
$ Width -> Env -> [Char] -> Note Symbol Ann -> [Char]
forall v a.
(Var v, Annotated a, Show a, Ord a) =>
Width -> Env -> [Char] -> Note v a -> [Char]
PrintError.renderNoteAsANSI Width
60 Env
env [Char]
source

ppEnv :: PPE.PrettyPrintEnv
ppEnv :: Env
ppEnv = Namer -> Suffixifier -> Env
PPE.makePPE (Int -> Names -> Namer
PPE.hqNamer Int
10 Names
Builtin.names) Suffixifier
PPE.dontSuffixify