{-|
Module      : Idris.Core.TT
Description : The core language of Idris, TT.

License     : BSD3
Maintainer  : The Idris Community.

TT is the core language of Idris. The language has:

   * Full dependent types

   * A hierarchy of universes, with cumulativity: Type : Type1, Type1 : Type2, ...

   * Pattern matching letrec binding

   * (primitive types defined externally)

   Some technical stuff:

   * Typechecker is kept as simple as possible - no unification, just a checker for incomplete terms.

   * We have a simple collection of tactics which we use to elaborate source
     programs with implicit syntax into fully explicit terms.
-}
{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFoldable, DeriveFunctor,
             DeriveGeneric, DeriveTraversable, FlexibleContexts,
             FlexibleInstances, FunctionalDependencies, MultiParamTypeClasses,
             PatternGuards, TypeSynonymInstances #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
module Idris.Core.TT(
    AppStatus(..), ArithTy(..), Binder(..), Const(..), Ctxt(..)
  , ConstraintFC(..), DataOpt(..), DataOpts(..), Datatype(..)
  , Env(..), EnvTT(..), Err(..), Err'(..), ErrorReportPart(..)
  , FC(..), FC'(..), ImplicitInfo(..), IntTy(..), Name(..)
  , NameOutput(..), NameType(..), NativeTy(..), OutputAnnotation(..)
  , Provenance(..), Raw(..), RigCount(..), SpecialName(..), TC(..), Term(..)
  , TermSize(..), TextFormatting(..), TT(..),Type(..), TypeInfo(..)
  , UConstraint(..), UCs(..), UExp(..), Universe(..)
  , addAlist, addBinder, addDef, allTTNames, arity, bindAll
  , bindingOf, bindTyArgs, caseName, constDocs, constIsType, deleteDefExact
  , discard, emptyContext, emptyFC, explicitNames, fc_end, fc_fname
  , fc_start, fcIn, fileFC, finalise, fmapMB, forget, forgetEnv
  , freeNames, getArgTys, getRetTy, substRetTy, implicitable, instantiate, internalNS
  , intTyName, isInjective, isTypeConst, lookupCtxt
  , lookupCtxtExact, lookupCtxtName, mapCtxt, mkApp, nativeTyWidth
  , nextName, noOccurrence, nsroot, occurrences
  , pEraseType, pmap, pprintRaw, pprintTT, pprintTTClause, prettyEnv, psubst
  , pToV, pToVs, pureTerm, raw_apply, raw_unapply, refsIn, safeForget
  , safeForgetEnv, showCG, showEnv, showEnvDbg, showSep
  , sImplementationN, sMN, sNS, str, subst, substNames, substTerm
  , substV, sUN, tcname, termSmallerThan, tfail, thead, tnull
  , toAlist, traceWhen, txt, unApply, uniqueBinders, uniqueName
  , uniqueNameFrom, uniqueNameSet, unList, updateDef, vToP, weakenTm
  , rigPlus, rigMult, fstEnv, rigEnv, sndEnv, lookupBinder, envBinders
  , envZero
  ) where

import Util.Pretty hiding (Str)

-- Work around AMP without CPP
import Prelude (Bool(..), Double, Enum(..), Eq(..), FilePath, Int, Integer,
                Maybe(..), Monoid(..), Num(..), Ord(..), Ordering(..), Show(..),
                String, div, error, fst, max, min, mod, not, otherwise, read,
                snd, ($), (&&), (.), (||))

#if (MIN_VERSION_base(4,11,0))
import qualified Prelude as S (Semigroup(..))
#endif

import Control.Applicative (Alternative, Applicative(..))
import qualified Control.Applicative as A (Alternative(..))
import Control.DeepSeq (($!!))
import Control.Monad
import qualified Control.Monad.Fail as Fail
import Control.Monad.State.Strict
import Data.Binary hiding (get, put)
import Data.Char
import Data.Data (Data)
import Data.Foldable (Foldable)
import Data.List hiding (group, insert)
import qualified Data.Map.Strict as Map
import Data.Maybe (listToMaybe)
import Data.Set (Set, fromList, insert, member)
import qualified Data.Text as T
import Data.Traversable (Traversable)
import Data.Typeable (Typeable)
import Debug.Trace
import GHC.Generics (Generic)
import Numeric (showIntAtBase)
import Numeric.IEEE (IEEE(identicalIEEE))

data Option = TTypeInTType
            | CheckConv
  deriving Option -> Option -> Bool
(Option -> Option -> Bool)
-> (Option -> Option -> Bool) -> Eq Option
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Option -> Option -> Bool
== :: Option -> Option -> Bool
$c/= :: Option -> Option -> Bool
/= :: Option -> Option -> Bool
Eq

-- | Source location. These are typically produced by 'Idris.Parser.Stack.withExtent'
data FC = FC { FC -> String
_fc_fname :: String, -- ^ Filename
               FC -> (Int, Int)
_fc_start :: (Int, Int), -- ^ Line and column numbers for the start of the location span
               FC -> (Int, Int)
_fc_end :: (Int, Int) -- ^ Line and column numbers for the end of the location span
             }
        | NoFC -- ^ Locations for machine-generated terms
        | FileFC { _fc_fname :: String } -- ^ Locations with file only
  deriving (Typeable FC
Typeable FC =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> FC -> c FC)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FC)
-> (FC -> Constr)
-> (FC -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FC))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC))
-> ((forall b. Data b => b -> b) -> FC -> FC)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r)
-> (forall u. (forall d. Data d => d -> u) -> FC -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> FC -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FC -> m FC)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FC -> m FC)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FC -> m FC)
-> Data FC
FC -> Constr
FC -> DataType
(forall b. Data b => b -> b) -> FC -> FC
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FC -> u
forall u. (forall d. Data d => d -> u) -> FC -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FC -> m FC
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC -> m FC
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FC
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FC -> c FC
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FC)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FC -> c FC
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FC -> c FC
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FC
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FC
$ctoConstr :: FC -> Constr
toConstr :: FC -> Constr
$cdataTypeOf :: FC -> DataType
dataTypeOf :: FC -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FC)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FC)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC)
$cgmapT :: (forall b. Data b => b -> b) -> FC -> FC
gmapT :: (forall b. Data b => b -> b) -> FC -> FC
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FC -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FC -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FC -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FC -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FC -> m FC
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FC -> m FC
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC -> m FC
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC -> m FC
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC -> m FC
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC -> m FC
Data, (forall x. FC -> Rep FC x)
-> (forall x. Rep FC x -> FC) -> Generic FC
forall x. Rep FC x -> FC
forall x. FC -> Rep FC x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FC -> Rep FC x
from :: forall x. FC -> Rep FC x
$cto :: forall x. Rep FC x -> FC
to :: forall x. Rep FC x -> FC
Generic, Typeable, Eq FC
Eq FC =>
(FC -> FC -> Ordering)
-> (FC -> FC -> Bool)
-> (FC -> FC -> Bool)
-> (FC -> FC -> Bool)
-> (FC -> FC -> Bool)
-> (FC -> FC -> FC)
-> (FC -> FC -> FC)
-> Ord FC
FC -> FC -> Bool
FC -> FC -> Ordering
FC -> FC -> FC
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FC -> FC -> Ordering
compare :: FC -> FC -> Ordering
$c< :: FC -> FC -> Bool
< :: FC -> FC -> Bool
$c<= :: FC -> FC -> Bool
<= :: FC -> FC -> Bool
$c> :: FC -> FC -> Bool
> :: FC -> FC -> Bool
$c>= :: FC -> FC -> Bool
>= :: FC -> FC -> Bool
$cmax :: FC -> FC -> FC
max :: FC -> FC -> FC
$cmin :: FC -> FC -> FC
min :: FC -> FC -> FC
Ord)

-- TODO: find uses and destroy them, doing this case analysis at call sites
-- | Give a notion of filename associated with an FC
fc_fname :: FC -> String
fc_fname :: FC -> String
fc_fname (FC String
f (Int, Int)
_ (Int, Int)
_) = String
f
fc_fname FC
NoFC = String
"(no file)"
fc_fname (FileFC String
f) = String
f

-- TODO: find uses and destroy them, doing this case analysis at call sites
-- | Give a notion of start location associated with an FC
fc_start :: FC -> (Int, Int)
fc_start :: FC -> (Int, Int)
fc_start (FC String
_ (Int, Int)
start (Int, Int)
_) = (Int, Int)
start
fc_start FC
NoFC = (Int
0, Int
0)
fc_start (FileFC String
f) = (Int
0, Int
0)

-- TODO: find uses and destroy them, doing this case analysis at call sites
-- | Give a notion of end location associated with an FC
fc_end :: FC -> (Int, Int)
fc_end :: FC -> (Int, Int)
fc_end (FC String
_ (Int, Int)
_ (Int, Int)
end) = (Int, Int)
end
fc_end FC
NoFC = (Int
0, Int
0)
fc_end (FileFC String
f) = (Int
0, Int
0)

#if (MIN_VERSION_base(4,11,0))
instance S.Semigroup FC where
    <> :: FC -> FC -> FC
(<>) = FC -> FC -> FC
forall a. Monoid a => a -> a -> a
mappend
#endif

instance Monoid FC where
  mempty :: FC
mempty = FC
NoFC

  -- | Get the largest span containing the two FCs
  mappend :: FC -> FC -> FC
mappend (FC String
f (Int, Int)
start (Int, Int)
end) (FC String
f' (Int, Int)
start' (Int, Int)
end')
      | String
f String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
f' = String -> (Int, Int) -> (Int, Int) -> FC
FC String
f ((Int, Int) -> (Int, Int) -> (Int, Int)
forall a. Ord a => a -> a -> a
min (Int, Int)
start (Int, Int)
start') ((Int, Int) -> (Int, Int) -> (Int, Int)
forall a. Ord a => a -> a -> a
max (Int, Int)
end (Int, Int)
end')
      | Bool
otherwise = FC
NoFC
  mappend fc :: FC
fc@(FC String
f (Int, Int)
_ (Int, Int)
_) (FileFC String
f') | String
f String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
f' = FC
fc
                                    | Bool
otherwise = FC
NoFC
  mappend (FileFC String
f') fc :: FC
fc@(FC String
f (Int, Int)
_ (Int, Int)
_) | String
f String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
f' = FC
fc
                                    | Bool
otherwise = FC
NoFC
  mappend (FileFC String
f) (FileFC String
f') | String
f String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
f' = String -> FC
FileFC String
f
                                 | Bool
otherwise = FC
NoFC
  mappend FC
NoFC FC
fc = FC
fc
  mappend FC
fc FC
NoFC = FC
fc


-- | Determine whether the first argument is completely contained in the second
fcIn :: FC -> FC -> Bool
fcIn :: FC -> FC -> Bool
fcIn FC
NoFC   FC
_ = Bool
False
fcIn (FileFC String
_) FC
_ = Bool
False
fcIn (FC {}) FC
NoFC = Bool
False
fcIn (FC {}) (FileFC String
_) = Bool
False
fcIn (FC String
fn1 (Int
sl1, Int
sc1) (Int
el1, Int
ec1)) (FC String
fn2 (Int
sl2, Int
sc2) (Int
el2, Int
ec2)) =
  String
fn1 String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
fn2 Bool -> Bool -> Bool
&&
  (Int
sl1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
sl2 Bool -> Bool -> Bool
&& Int
sc1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
sc2 Bool -> Bool -> Bool
|| Int
sl1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
sl2) Bool -> Bool -> Bool
&&
  (Int
el1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
el2 Bool -> Bool -> Bool
&& Int
ec1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
ec2 Bool -> Bool -> Bool
|| Int
el1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
el2)

-- | Ignore source location equality (so deriving classes do not compare FCs)
instance Eq FC where
  FC
_ == :: FC -> FC -> Bool
== FC
_ = Bool
True

-- | FC with equality
newtype FC' = FC' { FC' -> FC
unwrapFC :: FC } deriving (Typeable FC'
Typeable FC' =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> FC' -> c FC')
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FC')
-> (FC' -> Constr)
-> (FC' -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FC'))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC'))
-> ((forall b. Data b => b -> b) -> FC' -> FC')
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r)
-> (forall u. (forall d. Data d => d -> u) -> FC' -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> FC' -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FC' -> m FC')
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FC' -> m FC')
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FC' -> m FC')
-> Data FC'
FC' -> Constr
FC' -> DataType
(forall b. Data b => b -> b) -> FC' -> FC'
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FC' -> u
forall u. (forall d. Data d => d -> u) -> FC' -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FC'
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FC' -> c FC'
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FC')
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC')
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FC' -> c FC'
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FC' -> c FC'
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FC'
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FC'
$ctoConstr :: FC' -> Constr
toConstr :: FC' -> Constr
$cdataTypeOf :: FC' -> DataType
dataTypeOf :: FC' -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FC')
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FC')
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC')
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FC')
$cgmapT :: (forall b. Data b => b -> b) -> FC' -> FC'
gmapT :: (forall b. Data b => b -> b) -> FC' -> FC'
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FC' -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FC' -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FC' -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FC' -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FC' -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FC' -> m FC'
Data, (forall x. FC' -> Rep FC' x)
-> (forall x. Rep FC' x -> FC') -> Generic FC'
forall x. Rep FC' x -> FC'
forall x. FC' -> Rep FC' x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FC' -> Rep FC' x
from :: forall x. FC' -> Rep FC' x
$cto :: forall x. Rep FC' x -> FC'
to :: forall x. Rep FC' x -> FC'
Generic, Typeable, Eq FC'
Eq FC' =>
(FC' -> FC' -> Ordering)
-> (FC' -> FC' -> Bool)
-> (FC' -> FC' -> Bool)
-> (FC' -> FC' -> Bool)
-> (FC' -> FC' -> Bool)
-> (FC' -> FC' -> FC')
-> (FC' -> FC' -> FC')
-> Ord FC'
FC' -> FC' -> Bool
FC' -> FC' -> Ordering
FC' -> FC' -> FC'
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FC' -> FC' -> Ordering
compare :: FC' -> FC' -> Ordering
$c< :: FC' -> FC' -> Bool
< :: FC' -> FC' -> Bool
$c<= :: FC' -> FC' -> Bool
<= :: FC' -> FC' -> Bool
$c> :: FC' -> FC' -> Bool
> :: FC' -> FC' -> Bool
$c>= :: FC' -> FC' -> Bool
>= :: FC' -> FC' -> Bool
$cmax :: FC' -> FC' -> FC'
max :: FC' -> FC' -> FC'
$cmin :: FC' -> FC' -> FC'
min :: FC' -> FC' -> FC'
Ord)

instance Eq FC' where
  FC' FC
fc == :: FC' -> FC' -> Bool
== FC' FC
fc' = FC -> FC -> Bool
fcEq FC
fc FC
fc'
    where fcEq :: FC -> FC -> Bool
fcEq (FC String
n (Int, Int)
s (Int, Int)
e) (FC String
n' (Int, Int)
s' (Int, Int)
e') = String
n String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
n' Bool -> Bool -> Bool
&& (Int, Int)
s (Int, Int) -> (Int, Int) -> Bool
forall a. Eq a => a -> a -> Bool
== (Int, Int)
s' Bool -> Bool -> Bool
&& (Int, Int)
e (Int, Int) -> (Int, Int) -> Bool
forall a. Eq a => a -> a -> Bool
== (Int, Int)
e'
          fcEq FC
NoFC FC
NoFC = Bool
True
          fcEq (FileFC String
f) (FileFC String
f') = String
f String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
f'
          fcEq FC
_ FC
_ = Bool
False

instance Show FC' where
  showsPrec :: Int -> FC' -> ShowS
showsPrec Int
d (FC' FC
fc) = Int -> FC -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
d FC
fc

-- | Empty source location
emptyFC :: FC
emptyFC :: FC
emptyFC = FC
NoFC

-- | Source location with file only
fileFC :: String -> FC
fileFC :: String -> FC
fileFC String
s = String -> FC
FileFC String
s

{-!
deriving instance Binary FC
!-}

instance Sized FC where
  size :: FC -> Int
size (FC String
f (Int, Int)
s (Int, Int)
e) = Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
f
  size FC
NoFC = Int
1
  size (FileFC String
f) = String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
f

instance Show FC where
    show :: FC -> String
show (FC String
f (Int, Int)
s (Int, Int)
e) = String
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Int, Int) -> (Int, Int) -> String
forall {a} {a}.
(Eq a, Eq a, Show a, Show a) =>
(a, a) -> (a, a) -> String
showLC (Int, Int)
s (Int, Int)
e
      where showLC :: (a, a) -> (a, a) -> String
showLC (a
sl, a
sc) (a
el, a
ec) | a
sl a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
el Bool -> Bool -> Bool
&& a
sc a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
ec = a -> String
forall a. Show a => a -> String
show a
sl String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
sc
                                     | a
sl a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
el             = a -> String
forall a. Show a => a -> String
show a
sl String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
sc String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"-" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
ec
                                     | Bool
otherwise            = a -> String
forall a. Show a => a -> String
show a
sl String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
sc String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"-" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
el String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
ec
    show FC
NoFC = String
"No location"
    show (FileFC String
f) = String
f

-- | Output annotation for pretty-printed name - decides colour
data NameOutput = TypeOutput | FunOutput | DataOutput | MetavarOutput | PostulateOutput deriving (Int -> NameOutput -> ShowS
[NameOutput] -> ShowS
NameOutput -> String
(Int -> NameOutput -> ShowS)
-> (NameOutput -> String)
-> ([NameOutput] -> ShowS)
-> Show NameOutput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NameOutput -> ShowS
showsPrec :: Int -> NameOutput -> ShowS
$cshow :: NameOutput -> String
show :: NameOutput -> String
$cshowList :: [NameOutput] -> ShowS
showList :: [NameOutput] -> ShowS
Show, NameOutput -> NameOutput -> Bool
(NameOutput -> NameOutput -> Bool)
-> (NameOutput -> NameOutput -> Bool) -> Eq NameOutput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameOutput -> NameOutput -> Bool
== :: NameOutput -> NameOutput -> Bool
$c/= :: NameOutput -> NameOutput -> Bool
/= :: NameOutput -> NameOutput -> Bool
Eq, Eq NameOutput
Eq NameOutput =>
(NameOutput -> NameOutput -> Ordering)
-> (NameOutput -> NameOutput -> Bool)
-> (NameOutput -> NameOutput -> Bool)
-> (NameOutput -> NameOutput -> Bool)
-> (NameOutput -> NameOutput -> Bool)
-> (NameOutput -> NameOutput -> NameOutput)
-> (NameOutput -> NameOutput -> NameOutput)
-> Ord NameOutput
NameOutput -> NameOutput -> Bool
NameOutput -> NameOutput -> Ordering
NameOutput -> NameOutput -> NameOutput
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NameOutput -> NameOutput -> Ordering
compare :: NameOutput -> NameOutput -> Ordering
$c< :: NameOutput -> NameOutput -> Bool
< :: NameOutput -> NameOutput -> Bool
$c<= :: NameOutput -> NameOutput -> Bool
<= :: NameOutput -> NameOutput -> Bool
$c> :: NameOutput -> NameOutput -> Bool
> :: NameOutput -> NameOutput -> Bool
$c>= :: NameOutput -> NameOutput -> Bool
>= :: NameOutput -> NameOutput -> Bool
$cmax :: NameOutput -> NameOutput -> NameOutput
max :: NameOutput -> NameOutput -> NameOutput
$cmin :: NameOutput -> NameOutput -> NameOutput
min :: NameOutput -> NameOutput -> NameOutput
Ord, (forall x. NameOutput -> Rep NameOutput x)
-> (forall x. Rep NameOutput x -> NameOutput) -> Generic NameOutput
forall x. Rep NameOutput x -> NameOutput
forall x. NameOutput -> Rep NameOutput x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NameOutput -> Rep NameOutput x
from :: forall x. NameOutput -> Rep NameOutput x
$cto :: forall x. Rep NameOutput x -> NameOutput
to :: forall x. Rep NameOutput x -> NameOutput
Generic)

-- | Text formatting output
data TextFormatting = BoldText | ItalicText | UnderlineText deriving (Int -> TextFormatting -> ShowS
[TextFormatting] -> ShowS
TextFormatting -> String
(Int -> TextFormatting -> ShowS)
-> (TextFormatting -> String)
-> ([TextFormatting] -> ShowS)
-> Show TextFormatting
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextFormatting -> ShowS
showsPrec :: Int -> TextFormatting -> ShowS
$cshow :: TextFormatting -> String
show :: TextFormatting -> String
$cshowList :: [TextFormatting] -> ShowS
showList :: [TextFormatting] -> ShowS
Show, TextFormatting -> TextFormatting -> Bool
(TextFormatting -> TextFormatting -> Bool)
-> (TextFormatting -> TextFormatting -> Bool) -> Eq TextFormatting
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextFormatting -> TextFormatting -> Bool
== :: TextFormatting -> TextFormatting -> Bool
$c/= :: TextFormatting -> TextFormatting -> Bool
/= :: TextFormatting -> TextFormatting -> Bool
Eq, Eq TextFormatting
Eq TextFormatting =>
(TextFormatting -> TextFormatting -> Ordering)
-> (TextFormatting -> TextFormatting -> Bool)
-> (TextFormatting -> TextFormatting -> Bool)
-> (TextFormatting -> TextFormatting -> Bool)
-> (TextFormatting -> TextFormatting -> Bool)
-> (TextFormatting -> TextFormatting -> TextFormatting)
-> (TextFormatting -> TextFormatting -> TextFormatting)
-> Ord TextFormatting
TextFormatting -> TextFormatting -> Bool
TextFormatting -> TextFormatting -> Ordering
TextFormatting -> TextFormatting -> TextFormatting
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TextFormatting -> TextFormatting -> Ordering
compare :: TextFormatting -> TextFormatting -> Ordering
$c< :: TextFormatting -> TextFormatting -> Bool
< :: TextFormatting -> TextFormatting -> Bool
$c<= :: TextFormatting -> TextFormatting -> Bool
<= :: TextFormatting -> TextFormatting -> Bool
$c> :: TextFormatting -> TextFormatting -> Bool
> :: TextFormatting -> TextFormatting -> Bool
$c>= :: TextFormatting -> TextFormatting -> Bool
>= :: TextFormatting -> TextFormatting -> Bool
$cmax :: TextFormatting -> TextFormatting -> TextFormatting
max :: TextFormatting -> TextFormatting -> TextFormatting
$cmin :: TextFormatting -> TextFormatting -> TextFormatting
min :: TextFormatting -> TextFormatting -> TextFormatting
Ord, (forall x. TextFormatting -> Rep TextFormatting x)
-> (forall x. Rep TextFormatting x -> TextFormatting)
-> Generic TextFormatting
forall x. Rep TextFormatting x -> TextFormatting
forall x. TextFormatting -> Rep TextFormatting x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TextFormatting -> Rep TextFormatting x
from :: forall x. TextFormatting -> Rep TextFormatting x
$cto :: forall x. Rep TextFormatting x -> TextFormatting
to :: forall x. Rep TextFormatting x -> TextFormatting
Generic)

-- | Output annotations for pretty-printing
data OutputAnnotation = AnnName Name (Maybe NameOutput) (Maybe String) (Maybe String)
                        -- ^^ The name, classification, docs overview, and pretty-printed type
                      | AnnBoundName Name Bool
                        -- ^^ The name and whether it is implicit
                      | AnnConst Const
                      | AnnData String String -- ^ type, doc overview
                      | AnnType String String -- ^ name, doc overview
                      | AnnKeyword
                      | AnnFC FC
                      | AnnTextFmt TextFormatting
                      | AnnLink String -- ^ A link to this URL
                      | AnnTerm [(Name, Bool)] (TT Name) -- ^ pprint bound vars, original term
                      | AnnSearchResult Ordering -- ^ more general, isomorphic, or more specific
                      | AnnErr Err
                      | AnnNamespace [T.Text] (Maybe FilePath)
                        -- ^ A namespace (e.g. on an import line or in
                        -- a namespace declaration). Stored starting
                        -- at the root, with the hierarchy fully
                        -- resolved. If a file path is present, then
                        -- the namespace represents a module imported
                        -- from that file.
                      | AnnQuasiquote
                      | AnnAntiquote
                      | AnnSyntax String -- ^ type of syntax element: backslash or braces etc.
  deriving (Int -> OutputAnnotation -> ShowS
[OutputAnnotation] -> ShowS
OutputAnnotation -> String
(Int -> OutputAnnotation -> ShowS)
-> (OutputAnnotation -> String)
-> ([OutputAnnotation] -> ShowS)
-> Show OutputAnnotation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OutputAnnotation -> ShowS
showsPrec :: Int -> OutputAnnotation -> ShowS
$cshow :: OutputAnnotation -> String
show :: OutputAnnotation -> String
$cshowList :: [OutputAnnotation] -> ShowS
showList :: [OutputAnnotation] -> ShowS
Show, OutputAnnotation -> OutputAnnotation -> Bool
(OutputAnnotation -> OutputAnnotation -> Bool)
-> (OutputAnnotation -> OutputAnnotation -> Bool)
-> Eq OutputAnnotation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OutputAnnotation -> OutputAnnotation -> Bool
== :: OutputAnnotation -> OutputAnnotation -> Bool
$c/= :: OutputAnnotation -> OutputAnnotation -> Bool
/= :: OutputAnnotation -> OutputAnnotation -> Bool
Eq, (forall x. OutputAnnotation -> Rep OutputAnnotation x)
-> (forall x. Rep OutputAnnotation x -> OutputAnnotation)
-> Generic OutputAnnotation
forall x. Rep OutputAnnotation x -> OutputAnnotation
forall x. OutputAnnotation -> Rep OutputAnnotation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OutputAnnotation -> Rep OutputAnnotation x
from :: forall x. OutputAnnotation -> Rep OutputAnnotation x
$cto :: forall x. Rep OutputAnnotation x -> OutputAnnotation
to :: forall x. Rep OutputAnnotation x -> OutputAnnotation
Generic, Eq OutputAnnotation
Eq OutputAnnotation =>
(OutputAnnotation -> OutputAnnotation -> Ordering)
-> (OutputAnnotation -> OutputAnnotation -> Bool)
-> (OutputAnnotation -> OutputAnnotation -> Bool)
-> (OutputAnnotation -> OutputAnnotation -> Bool)
-> (OutputAnnotation -> OutputAnnotation -> Bool)
-> (OutputAnnotation -> OutputAnnotation -> OutputAnnotation)
-> (OutputAnnotation -> OutputAnnotation -> OutputAnnotation)
-> Ord OutputAnnotation
OutputAnnotation -> OutputAnnotation -> Bool
OutputAnnotation -> OutputAnnotation -> Ordering
OutputAnnotation -> OutputAnnotation -> OutputAnnotation
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: OutputAnnotation -> OutputAnnotation -> Ordering
compare :: OutputAnnotation -> OutputAnnotation -> Ordering
$c< :: OutputAnnotation -> OutputAnnotation -> Bool
< :: OutputAnnotation -> OutputAnnotation -> Bool
$c<= :: OutputAnnotation -> OutputAnnotation -> Bool
<= :: OutputAnnotation -> OutputAnnotation -> Bool
$c> :: OutputAnnotation -> OutputAnnotation -> Bool
> :: OutputAnnotation -> OutputAnnotation -> Bool
$c>= :: OutputAnnotation -> OutputAnnotation -> Bool
>= :: OutputAnnotation -> OutputAnnotation -> Bool
$cmax :: OutputAnnotation -> OutputAnnotation -> OutputAnnotation
max :: OutputAnnotation -> OutputAnnotation -> OutputAnnotation
$cmin :: OutputAnnotation -> OutputAnnotation -> OutputAnnotation
min :: OutputAnnotation -> OutputAnnotation -> OutputAnnotation
Ord)

-- | Used for error reflection
data ErrorReportPart = TextPart String
                     | NamePart Name
                     | TermPart Term
                     | RawPart Raw
                     | SubReport [ErrorReportPart]
                       deriving (Int -> ErrorReportPart -> ShowS
[ErrorReportPart] -> ShowS
ErrorReportPart -> String
(Int -> ErrorReportPart -> ShowS)
-> (ErrorReportPart -> String)
-> ([ErrorReportPart] -> ShowS)
-> Show ErrorReportPart
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ErrorReportPart -> ShowS
showsPrec :: Int -> ErrorReportPart -> ShowS
$cshow :: ErrorReportPart -> String
show :: ErrorReportPart -> String
$cshowList :: [ErrorReportPart] -> ShowS
showList :: [ErrorReportPart] -> ShowS
Show, ErrorReportPart -> ErrorReportPart -> Bool
(ErrorReportPart -> ErrorReportPart -> Bool)
-> (ErrorReportPart -> ErrorReportPart -> Bool)
-> Eq ErrorReportPart
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ErrorReportPart -> ErrorReportPart -> Bool
== :: ErrorReportPart -> ErrorReportPart -> Bool
$c/= :: ErrorReportPart -> ErrorReportPart -> Bool
/= :: ErrorReportPart -> ErrorReportPart -> Bool
Eq, Eq ErrorReportPart
Eq ErrorReportPart =>
(ErrorReportPart -> ErrorReportPart -> Ordering)
-> (ErrorReportPart -> ErrorReportPart -> Bool)
-> (ErrorReportPart -> ErrorReportPart -> Bool)
-> (ErrorReportPart -> ErrorReportPart -> Bool)
-> (ErrorReportPart -> ErrorReportPart -> Bool)
-> (ErrorReportPart -> ErrorReportPart -> ErrorReportPart)
-> (ErrorReportPart -> ErrorReportPart -> ErrorReportPart)
-> Ord ErrorReportPart
ErrorReportPart -> ErrorReportPart -> Bool
ErrorReportPart -> ErrorReportPart -> Ordering
ErrorReportPart -> ErrorReportPart -> ErrorReportPart
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ErrorReportPart -> ErrorReportPart -> Ordering
compare :: ErrorReportPart -> ErrorReportPart -> Ordering
$c< :: ErrorReportPart -> ErrorReportPart -> Bool
< :: ErrorReportPart -> ErrorReportPart -> Bool
$c<= :: ErrorReportPart -> ErrorReportPart -> Bool
<= :: ErrorReportPart -> ErrorReportPart -> Bool
$c> :: ErrorReportPart -> ErrorReportPart -> Bool
> :: ErrorReportPart -> ErrorReportPart -> Bool
$c>= :: ErrorReportPart -> ErrorReportPart -> Bool
>= :: ErrorReportPart -> ErrorReportPart -> Bool
$cmax :: ErrorReportPart -> ErrorReportPart -> ErrorReportPart
max :: ErrorReportPart -> ErrorReportPart -> ErrorReportPart
$cmin :: ErrorReportPart -> ErrorReportPart -> ErrorReportPart
min :: ErrorReportPart -> ErrorReportPart -> ErrorReportPart
Ord, Typeable ErrorReportPart
Typeable ErrorReportPart =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> ErrorReportPart -> c ErrorReportPart)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ErrorReportPart)
-> (ErrorReportPart -> Constr)
-> (ErrorReportPart -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ErrorReportPart))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ErrorReportPart))
-> ((forall b. Data b => b -> b)
    -> ErrorReportPart -> ErrorReportPart)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> ErrorReportPart -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ErrorReportPart -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> ErrorReportPart -> m ErrorReportPart)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ErrorReportPart -> m ErrorReportPart)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ErrorReportPart -> m ErrorReportPart)
-> Data ErrorReportPart
ErrorReportPart -> Constr
ErrorReportPart -> DataType
(forall b. Data b => b -> b) -> ErrorReportPart -> ErrorReportPart
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> ErrorReportPart -> u
forall u. (forall d. Data d => d -> u) -> ErrorReportPart -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ErrorReportPart
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ErrorReportPart -> c ErrorReportPart
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ErrorReportPart)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ErrorReportPart)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ErrorReportPart -> c ErrorReportPart
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ErrorReportPart -> c ErrorReportPart
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ErrorReportPart
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ErrorReportPart
$ctoConstr :: ErrorReportPart -> Constr
toConstr :: ErrorReportPart -> Constr
$cdataTypeOf :: ErrorReportPart -> DataType
dataTypeOf :: ErrorReportPart -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ErrorReportPart)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ErrorReportPart)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ErrorReportPart)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ErrorReportPart)
$cgmapT :: (forall b. Data b => b -> b) -> ErrorReportPart -> ErrorReportPart
gmapT :: (forall b. Data b => b -> b) -> ErrorReportPart -> ErrorReportPart
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorReportPart -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ErrorReportPart -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ErrorReportPart -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ErrorReportPart -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ErrorReportPart -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ErrorReportPart -> m ErrorReportPart
Data, (forall x. ErrorReportPart -> Rep ErrorReportPart x)
-> (forall x. Rep ErrorReportPart x -> ErrorReportPart)
-> Generic ErrorReportPart
forall x. Rep ErrorReportPart x -> ErrorReportPart
forall x. ErrorReportPart -> Rep ErrorReportPart x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ErrorReportPart -> Rep ErrorReportPart x
from :: forall x. ErrorReportPart -> Rep ErrorReportPart x
$cto :: forall x. Rep ErrorReportPart x -> ErrorReportPart
to :: forall x. Rep ErrorReportPart x -> ErrorReportPart
Generic, Typeable)


data Provenance = ExpectedType
                | TooManyArgs Term
                | InferredVal
                | GivenVal
                | SourceTerm Term
  deriving (Int -> Provenance -> ShowS
[Provenance] -> ShowS
Provenance -> String
(Int -> Provenance -> ShowS)
-> (Provenance -> String)
-> ([Provenance] -> ShowS)
-> Show Provenance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Provenance -> ShowS
showsPrec :: Int -> Provenance -> ShowS
$cshow :: Provenance -> String
show :: Provenance -> String
$cshowList :: [Provenance] -> ShowS
showList :: [Provenance] -> ShowS
Show, Provenance -> Provenance -> Bool
(Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool) -> Eq Provenance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Provenance -> Provenance -> Bool
== :: Provenance -> Provenance -> Bool
$c/= :: Provenance -> Provenance -> Bool
/= :: Provenance -> Provenance -> Bool
Eq, Eq Provenance
Eq Provenance =>
(Provenance -> Provenance -> Ordering)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Provenance)
-> (Provenance -> Provenance -> Provenance)
-> Ord Provenance
Provenance -> Provenance -> Bool
Provenance -> Provenance -> Ordering
Provenance -> Provenance -> Provenance
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Provenance -> Provenance -> Ordering
compare :: Provenance -> Provenance -> Ordering
$c< :: Provenance -> Provenance -> Bool
< :: Provenance -> Provenance -> Bool
$c<= :: Provenance -> Provenance -> Bool
<= :: Provenance -> Provenance -> Bool
$c> :: Provenance -> Provenance -> Bool
> :: Provenance -> Provenance -> Bool
$c>= :: Provenance -> Provenance -> Bool
>= :: Provenance -> Provenance -> Bool
$cmax :: Provenance -> Provenance -> Provenance
max :: Provenance -> Provenance -> Provenance
$cmin :: Provenance -> Provenance -> Provenance
min :: Provenance -> Provenance -> Provenance
Ord, Typeable Provenance
Typeable Provenance =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Provenance -> c Provenance)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Provenance)
-> (Provenance -> Constr)
-> (Provenance -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Provenance))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c Provenance))
-> ((forall b. Data b => b -> b) -> Provenance -> Provenance)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Provenance -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Provenance -> r)
-> (forall u. (forall d. Data d => d -> u) -> Provenance -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Provenance -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Provenance -> m Provenance)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Provenance -> m Provenance)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Provenance -> m Provenance)
-> Data Provenance
Provenance -> Constr
Provenance -> DataType
(forall b. Data b => b -> b) -> Provenance -> Provenance
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Provenance -> u
forall u. (forall d. Data d => d -> u) -> Provenance -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Provenance -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Provenance -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Provenance
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Provenance -> c Provenance
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Provenance)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Provenance)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Provenance -> c Provenance
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Provenance -> c Provenance
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Provenance
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Provenance
$ctoConstr :: Provenance -> Constr
toConstr :: Provenance -> Constr
$cdataTypeOf :: Provenance -> DataType
dataTypeOf :: Provenance -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Provenance)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Provenance)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Provenance)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Provenance)
$cgmapT :: (forall b. Data b => b -> b) -> Provenance -> Provenance
gmapT :: (forall b. Data b => b -> b) -> Provenance -> Provenance
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Provenance -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Provenance -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Provenance -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Provenance -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Provenance -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Provenance -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Provenance -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Provenance -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Provenance -> m Provenance
Data, (forall x. Provenance -> Rep Provenance x)
-> (forall x. Rep Provenance x -> Provenance) -> Generic Provenance
forall x. Rep Provenance x -> Provenance
forall x. Provenance -> Rep Provenance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Provenance -> Rep Provenance x
from :: forall x. Provenance -> Rep Provenance x
$cto :: forall x. Rep Provenance x -> Provenance
to :: forall x. Rep Provenance x -> Provenance
Generic, Typeable)
{-!
deriving instance Binary Err
!-}


-- NB: Please remember to keep Err synchronised with
-- Language.Reflection.Errors.Err in the stdlib!

-- | Idris errors. Used as exceptions in the compiler, but reported to users
-- if they reach the top level.
data Err' t
          = Msg String
          | InternalMsg String
          | CantUnify Bool (t, Maybe Provenance) -- Expected type, provenance
                           (t, Maybe Provenance) -- Actual type, provenance
                           (Err' t) [(Name, t)] Int
               -- Int is 'score' - how much we did unify
               -- Bool indicates recoverability, True indicates more info may make
               -- unification succeed
          | InfiniteUnify Name t [(Name, t)]
          | CantConvert t t [(Name, t)]
          | CantSolveGoal t [(Name, t)]
          | UnifyScope Name Name t [(Name, t)]
          | CantInferType String
          | NonFunctionType t t
          | NotEquality t t
          | TooManyArguments Name
          | CantIntroduce t
          | NoSuchVariable Name
          | WithFnType t
          | NoTypeDecl Name
          | NotInjective t t t
          | CantResolve Bool -- True if postponed, False if fatal
                        t (Err' t) -- any further information
          | InvalidTCArg Name t
          | CantResolveAlts [Name]
          | NoValidAlts [Name]
          | IncompleteTerm t
          | UniverseError FC UExp (Int, Int) (Int, Int) [ConstraintFC]
            -- ^ Location, bad universe, old domain, new domain, suspects
          | UniqueError Universe Name
          | UniqueKindError Universe Name
          | ProgramLineComment
          | Inaccessible Name
          | UnknownImplicit Name Name
          | CantMatch t
          | NonCollapsiblePostulate Name
          | AlreadyDefined Name
          | ProofSearchFail (Err' t)
          | NoRewriting t t t
          | At FC (Err' t)
          | Elaborating String Name (Maybe t) (Err' t)
          | ElaboratingArg Name Name [(Name, Name)] (Err' t)
          | ProviderError String
          | LoadingFailed String (Err' t)
          | ReflectionError [[ErrorReportPart]] (Err' t)
          | ReflectionFailed String (Err' t)
          | ElabScriptDebug [ErrorReportPart] t [(Name, t, [(Name, Binder t)])]
            -- ^ User-specified message, proof term, goals with context (first goal is focused)
          | ElabScriptStuck t
          | RunningElabScript (Err' t) -- ^ The error occurred during a top-level elaboration script
          | ElabScriptStaging Name
          | FancyMsg [ErrorReportPart]
  deriving (Err' t -> Err' t -> Bool
(Err' t -> Err' t -> Bool)
-> (Err' t -> Err' t -> Bool) -> Eq (Err' t)
forall t. Eq t => Err' t -> Err' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall t. Eq t => Err' t -> Err' t -> Bool
== :: Err' t -> Err' t -> Bool
$c/= :: forall t. Eq t => Err' t -> Err' t -> Bool
/= :: Err' t -> Err' t -> Bool
Eq, Eq (Err' t)
Eq (Err' t) =>
(Err' t -> Err' t -> Ordering)
-> (Err' t -> Err' t -> Bool)
-> (Err' t -> Err' t -> Bool)
-> (Err' t -> Err' t -> Bool)
-> (Err' t -> Err' t -> Bool)
-> (Err' t -> Err' t -> Err' t)
-> (Err' t -> Err' t -> Err' t)
-> Ord (Err' t)
Err' t -> Err' t -> Bool
Err' t -> Err' t -> Ordering
Err' t -> Err' t -> Err' t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall t. Ord t => Eq (Err' t)
forall t. Ord t => Err' t -> Err' t -> Bool
forall t. Ord t => Err' t -> Err' t -> Ordering
forall t. Ord t => Err' t -> Err' t -> Err' t
$ccompare :: forall t. Ord t => Err' t -> Err' t -> Ordering
compare :: Err' t -> Err' t -> Ordering
$c< :: forall t. Ord t => Err' t -> Err' t -> Bool
< :: Err' t -> Err' t -> Bool
$c<= :: forall t. Ord t => Err' t -> Err' t -> Bool
<= :: Err' t -> Err' t -> Bool
$c> :: forall t. Ord t => Err' t -> Err' t -> Bool
> :: Err' t -> Err' t -> Bool
$c>= :: forall t. Ord t => Err' t -> Err' t -> Bool
>= :: Err' t -> Err' t -> Bool
$cmax :: forall t. Ord t => Err' t -> Err' t -> Err' t
max :: Err' t -> Err' t -> Err' t
$cmin :: forall t. Ord t => Err' t -> Err' t -> Err' t
min :: Err' t -> Err' t -> Err' t
Ord, (forall a b. (a -> b) -> Err' a -> Err' b)
-> (forall a b. a -> Err' b -> Err' a) -> Functor Err'
forall a b. a -> Err' b -> Err' a
forall a b. (a -> b) -> Err' a -> Err' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Err' a -> Err' b
fmap :: forall a b. (a -> b) -> Err' a -> Err' b
$c<$ :: forall a b. a -> Err' b -> Err' a
<$ :: forall a b. a -> Err' b -> Err' a
Functor, Typeable (Err' t)
Typeable (Err' t) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Err' t -> c (Err' t))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Err' t))
-> (Err' t -> Constr)
-> (Err' t -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Err' t)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Err' t)))
-> ((forall b. Data b => b -> b) -> Err' t -> Err' t)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Err' t -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Err' t -> r)
-> (forall u. (forall d. Data d => d -> u) -> Err' t -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Err' t -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Err' t -> m (Err' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Err' t -> m (Err' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Err' t -> m (Err' t))
-> Data (Err' t)
Err' t -> Constr
Err' t -> DataType
(forall b. Data b => b -> b) -> Err' t -> Err' t
forall t. Data t => Typeable (Err' t)
forall t. Data t => Err' t -> Constr
forall t. Data t => Err' t -> DataType
forall t.
Data t =>
(forall b. Data b => b -> b) -> Err' t -> Err' t
forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> Err' t -> u
forall t u. Data t => (forall d. Data d => d -> u) -> Err' t -> [u]
forall t r r'.
Data t =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
forall t r r'.
Data t =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Err' t)
forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Err' t -> c (Err' t)
forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Err' t))
forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Err' t))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Err' t -> u
forall u. (forall d. Data d => d -> u) -> Err' t -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Err' t)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Err' t -> c (Err' t)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Err' t))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Err' t))
$cgfoldl :: forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Err' t -> c (Err' t)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Err' t -> c (Err' t)
$cgunfold :: forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Err' t)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Err' t)
$ctoConstr :: forall t. Data t => Err' t -> Constr
toConstr :: Err' t -> Constr
$cdataTypeOf :: forall t. Data t => Err' t -> DataType
dataTypeOf :: Err' t -> DataType
$cdataCast1 :: forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Err' t))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Err' t))
$cdataCast2 :: forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Err' t))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Err' t))
$cgmapT :: forall t.
Data t =>
(forall b. Data b => b -> b) -> Err' t -> Err' t
gmapT :: (forall b. Data b => b -> b) -> Err' t -> Err' t
$cgmapQl :: forall t r r'.
Data t =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
$cgmapQr :: forall t r r'.
Data t =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Err' t -> r
$cgmapQ :: forall t u. Data t => (forall d. Data d => d -> u) -> Err' t -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Err' t -> [u]
$cgmapQi :: forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> Err' t -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Err' t -> u
$cgmapM :: forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
$cgmapMp :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
$cgmapMo :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Err' t -> m (Err' t)
Data, (forall x. Err' t -> Rep (Err' t) x)
-> (forall x. Rep (Err' t) x -> Err' t) -> Generic (Err' t)
forall x. Rep (Err' t) x -> Err' t
forall x. Err' t -> Rep (Err' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (Err' t) x -> Err' t
forall t x. Err' t -> Rep (Err' t) x
$cfrom :: forall t x. Err' t -> Rep (Err' t) x
from :: forall x. Err' t -> Rep (Err' t) x
$cto :: forall t x. Rep (Err' t) x -> Err' t
to :: forall x. Rep (Err' t) x -> Err' t
Generic, Typeable)

type Err = Err' Term

data TC a = OK !a
          | Error Err
  deriving (TC a -> TC a -> Bool
(TC a -> TC a -> Bool) -> (TC a -> TC a -> Bool) -> Eq (TC a)
forall a. Eq a => TC a -> TC a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => TC a -> TC a -> Bool
== :: TC a -> TC a -> Bool
$c/= :: forall a. Eq a => TC a -> TC a -> Bool
/= :: TC a -> TC a -> Bool
Eq, (forall a b. (a -> b) -> TC a -> TC b)
-> (forall a b. a -> TC b -> TC a) -> Functor TC
forall a b. a -> TC b -> TC a
forall a b. (a -> b) -> TC a -> TC b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> TC a -> TC b
fmap :: forall a b. (a -> b) -> TC a -> TC b
$c<$ :: forall a b. a -> TC b -> TC a
<$ :: forall a b. a -> TC b -> TC a
Functor)

bindTC :: TC a -> (a -> TC b) -> TC b
bindTC :: forall a b. TC a -> (a -> TC b) -> TC b
bindTC TC a
x a -> TC b
k = case TC a
x of
                OK a
v -> a -> TC b
k a
v
                Error Err
e -> Err -> TC b
forall a. Err -> TC a
Error Err
e
{-# INLINE bindTC #-}

instance Monad TC where
    return :: forall a. a -> TC a
return a
x = a -> TC a
forall a. a -> TC a
OK a
x
    TC a
x >>= :: forall a b. TC a -> (a -> TC b) -> TC b
>>= a -> TC b
k = TC a -> (a -> TC b) -> TC b
forall a b. TC a -> (a -> TC b) -> TC b
bindTC TC a
x a -> TC b
k
#if !(MIN_VERSION_base(4,13,0))
    fail = Fail.fail
#endif

instance Fail.MonadFail TC where
    fail :: forall a. String -> TC a
fail String
e = Err -> TC a
forall a. Err -> TC a
Error (String -> Err
forall t. String -> Err' t
InternalMsg String
e)

instance MonadPlus TC where
    mzero :: forall a. TC a
mzero = String -> TC a
forall a. String -> TC a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Unknown error"
    (OK a
x) mplus :: forall a. TC a -> TC a -> TC a
`mplus` TC a
_ = a -> TC a
forall a. a -> TC a
OK a
x
    TC a
_ `mplus` (OK a
y) = a -> TC a
forall a. a -> TC a
OK a
y
    TC a
err `mplus` TC a
_    = TC a
err


instance Applicative TC where
    pure :: forall a. a -> TC a
pure = a -> TC a
forall a. a -> TC a
forall (m :: * -> *) a. Monad m => a -> m a
return
    <*> :: forall a b. TC (a -> b) -> TC a -> TC b
(<*>) = TC (a -> b) -> TC a -> TC b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

instance Alternative TC where
    empty :: forall a. TC a
empty = TC a
forall a. TC a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
    <|> :: forall a. TC a -> TC a -> TC a
(<|>) = TC a -> TC a -> TC a
forall a. TC a -> TC a -> TC a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus

instance Sized ErrorReportPart where
  size :: ErrorReportPart -> Int
size (TextPart String
msg) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
msg
  size (TermPart TT Name
t) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
t
  size (RawPart Raw
r) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Raw -> Int
forall a. Sized a => a -> Int
size Raw
r
  size (NamePart Name
n) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
n
  size (SubReport [ErrorReportPart]
rs) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [ErrorReportPart] -> Int
forall a. Sized a => a -> Int
size [ErrorReportPart]
rs

instance Sized Err where
  size :: Err -> Int
size (Msg String
msg) = String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
msg
  size (InternalMsg String
msg) = String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
msg
  size (CantUnify Bool
_ (TT Name, Maybe Provenance)
left (TT Name, Maybe Provenance)
right Err
err [(Name, TT Name)]
_ Int
score) = TT Name -> Int
forall a. Sized a => a -> Int
size ((TT Name, Maybe Provenance) -> TT Name
forall a b. (a, b) -> a
fst (TT Name, Maybe Provenance)
left) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT Name -> Int
forall a. Sized a => a -> Int
size ((TT Name, Maybe Provenance) -> TT Name
forall a b. (a, b) -> a
fst (TT Name, Maybe Provenance)
right) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Err -> Int
forall a. Sized a => a -> Int
size Err
err
  size (InfiniteUnify Name
_ TT Name
right [(Name, TT Name)]
_) = TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
right
  size (CantConvert TT Name
left TT Name
right [(Name, TT Name)]
_) = TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
right
  size (UnifyScope Name
_ Name
_ TT Name
right [(Name, TT Name)]
_) = TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
right
  size (NoSuchVariable Name
name) = Name -> Int
forall a. Sized a => a -> Int
size Name
name
  size (NoTypeDecl Name
name) = Name -> Int
forall a. Sized a => a -> Int
size Name
name
  size (NotInjective TT Name
l TT Name
c TT Name
r) = TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
r
  size (CantResolve Bool
_ TT Name
trm Err
_) = TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
trm
  size (NoRewriting TT Name
l TT Name
r TT Name
t) = TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
r Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
t
  size (CantResolveAlts [Name]
_) = Int
1
  size (IncompleteTerm TT Name
trm) = TT Name -> Int
forall a. Sized a => a -> Int
size TT Name
trm
  size Err
ProgramLineComment = Int
1
  size (At FC
fc Err
err) = FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Err -> Int
forall a. Sized a => a -> Int
size Err
err
  size (Elaborating String
_ Name
_ Maybe (TT Name)
_ Err
err) = Err -> Int
forall a. Sized a => a -> Int
size Err
err
  size (ElaboratingArg Name
_ Name
_ [(Name, Name)]
_ Err
err) = Err -> Int
forall a. Sized a => a -> Int
size Err
err
  size (ProviderError String
msg) = String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
msg
  size (LoadingFailed String
fn Err
e) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
fn Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Err -> Int
forall a. Sized a => a -> Int
size Err
e
  size Err
_ = Int
1

instance Show Err where
    show :: Err -> String
show (Msg String
s) = String
s
    show (InternalMsg String
s) = String
"Internal error: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
s
    show (CantUnify Bool
rcv (TT Name, Maybe Provenance)
l (TT Name, Maybe Provenance)
r Err
e [(Name, TT Name)]
sc Int
i) = String
"CantUnify " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Bool -> String
forall a. Show a => a -> String
show Bool
rcv String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                         (TT Name, Maybe Provenance) -> String
forall a. Show a => a -> String
show (TT Name, Maybe Provenance)
l String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" and " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (TT Name, Maybe Provenance) -> String
forall a. Show a => a -> String
show (TT Name, Maybe Provenance)
r String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                         Err -> String
forall a. Show a => a -> String
show Err
e String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [(Name, TT Name)] -> String
forall a. Show a => a -> String
show [(Name, TT Name)]
sc String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    show (CantConvert TT Name
l TT Name
r [(Name, TT Name)]
sc) = String
"CantConvert " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                         TT Name -> String
forall a. Show a => a -> String
show TT Name
l String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" and " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TT Name -> String
forall a. Show a => a -> String
show TT Name
r String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                         String
" in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [(Name, TT Name)] -> String
forall a. Show a => a -> String
show [(Name, TT Name)]
sc
    show (CantSolveGoal TT Name
g [(Name, TT Name)]
_) = String
"CantSolve " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TT Name -> String
forall a. Show a => a -> String
show TT Name
g
    show (Inaccessible Name
n) = Name -> String
forall a. Show a => a -> String
show Name
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" is not an accessible pattern variable"
    show (UnknownImplicit Name
n Name
f) = Name -> String
forall a. Show a => a -> String
show Name
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" is not an implicit argument of " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
f
    show (ProviderError String
msg) = String
"Type provider error: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
msg
    show (LoadingFailed String
fn Err
e) = String
"Loading " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
fn String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" failed: (TT) " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Err -> String
forall a. Show a => a -> String
show Err
e
    show Err
ProgramLineComment = String
"Program line next to comment"
    show (At FC
f Err
e) = FC -> String
forall a. Show a => a -> String
show FC
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Err -> String
forall a. Show a => a -> String
show Err
e
    show (ElaboratingArg Name
f Name
x [(Name, Name)]
prev Err
e) = String
"Elaborating " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" arg " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                       Name -> String
forall a. Show a => a -> String
show Name
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
": " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Err -> String
forall a. Show a => a -> String
show Err
e
    show (Elaborating String
what Name
n Maybe (TT Name)
ty Err
e) = String
"Elaborating " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
what String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
n String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                     Maybe (TT Name) -> String
forall {a}. Show a => Maybe a -> String
showType Maybe (TT Name)
ty String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Err -> String
forall a. Show a => a -> String
show Err
e
        where
          showType :: Maybe a -> String
showType Maybe a
Nothing = String
""
          showType (Just a
ty) = String
" with expected type " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
ty
    show (ProofSearchFail Err
e) = String
"Proof search fail: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Err -> String
forall a. Show a => a -> String
show Err
e
    show (InfiniteUnify Name
_ TT Name
_ [(Name, TT Name)]
_) = String
"InfiniteUnify"
    show (UnifyScope Name
_ Name
_ TT Name
_ [(Name, TT Name)]
_) = String
"UnifyScope"
    show (NonFunctionType TT Name
_ TT Name
_) = String
"NonFunctionType"
    show (NotEquality TT Name
_ TT Name
_) = String
"NotEquality"
    show (TooManyArguments Name
_) = String
"TooManyArguments"
    show (CantIntroduce TT Name
_) = String
"CantIntroduce"
    show (NoSuchVariable Name
n) = String
"NoSuchVariable " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
n
    show (WithFnType TT Name
_) = String
"WithFnType"
    show (NoTypeDecl Name
_) = String
"NoTypeDecl"
    show (NotInjective TT Name
_ TT Name
_ TT Name
_) = String
"NotInjective"
    show (CantResolve Bool
_ TT Name
_ Err
_) = String
"CantResolve"
    show (InvalidTCArg Name
_ TT Name
_) = String
"InvalidTCArg"
    show (CantResolveAlts [Name]
_) = String
"CantResolveAlts"
    show (NoValidAlts [Name]
_) = String
"NoValidAlts"
    show (IncompleteTerm TT Name
_) = String
"IncompleteTerm"
    show Err
_ = String
"Error"

instance Pretty Err OutputAnnotation where
  pretty :: Err -> Doc OutputAnnotation
pretty (Msg String
m) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
m
  pretty (CantUnify Bool
_ (TT Name
l, Maybe Provenance
_) (TT Name
r, Maybe Provenance
_) Err
e [(Name, TT Name)]
_ Int
i) =
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Cannot unify" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> TT Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty TT Name
l Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"and" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> TT Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty TT Name
r Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
nest Int
nestingSize (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"where" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Err -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Err
e Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"with" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Int -> String) -> Int -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> Doc OutputAnnotation) -> Int -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Int
i))
  pretty (ProviderError String
msg) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
msg
  pretty err :: Err
err@(LoadingFailed String
_ Err
_) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Err -> String
forall a. Show a => a -> String
show Err
err)
  pretty Err
_ = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Error"

instance (Pretty a OutputAnnotation) => Pretty (TC a) OutputAnnotation where
  pretty :: TC a -> Doc OutputAnnotation
pretty (OK a
ok) = a -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty a
ok
  pretty (Error Err
err) =
    String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Error" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Err -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Err
err

instance Show a => Show (TC a) where
    show :: TC a -> String
show (OK a
x) = a -> String
forall a. Show a => a -> String
show a
x
    show (Error Err
str) = String
"Error: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Err -> String
forall a. Show a => a -> String
show Err
str

tfail :: Err -> TC a
tfail :: forall a. Err -> TC a
tfail Err
e = Err -> TC a
forall a. Err -> TC a
Error Err
e

discard :: Monad m => m a -> m ()
discard :: forall (m :: * -> *) a. Monad m => m a -> m ()
discard m a
f = m a
f m a -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

showSep :: String -> [String] -> String
showSep :: String -> [String] -> String
showSep String
sep [] = String
""
showSep String
sep [String
x] = String
x
showSep String
sep (String
x:[String]
xs) = String
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
sep String -> ShowS
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
showSep String
sep [String]
xs

pmap :: (t -> b) -> (t, t) -> (b, b)
pmap t -> b
f (t
x, t
y) = (t -> b
f t
x, t -> b
f t
y)

traceWhen :: Bool -> String -> a -> a
traceWhen Bool
True String
msg a
a = String -> a -> a
forall a. String -> a -> a
trace String
msg a
a
traceWhen Bool
False String
_  a
a = a
a

-- RAW TERMS ----------------------------------------------------------------

-- | Names are hierarchies of strings, describing scope (so no danger of
-- duplicate names, but need to be careful on lookup).
data Name = UN !T.Text -- ^ User-provided name
          | NS !Name [T.Text] -- ^ Root, namespaces
          | MN !Int !T.Text -- ^ Machine chosen names
          | SN !SpecialName -- ^ Decorated function names
          | SymRef Int -- ^ Reference to IBC file symbol table (used during serialisation)
  deriving (Name -> Name -> Bool
(Name -> Name -> Bool) -> (Name -> Name -> Bool) -> Eq Name
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Name -> Name -> Bool
== :: Name -> Name -> Bool
$c/= :: Name -> Name -> Bool
/= :: Name -> Name -> Bool
Eq, Eq Name
Eq Name =>
(Name -> Name -> Ordering)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Name)
-> (Name -> Name -> Name)
-> Ord Name
Name -> Name -> Bool
Name -> Name -> Ordering
Name -> Name -> Name
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Name -> Name -> Ordering
compare :: Name -> Name -> Ordering
$c< :: Name -> Name -> Bool
< :: Name -> Name -> Bool
$c<= :: Name -> Name -> Bool
<= :: Name -> Name -> Bool
$c> :: Name -> Name -> Bool
> :: Name -> Name -> Bool
$c>= :: Name -> Name -> Bool
>= :: Name -> Name -> Bool
$cmax :: Name -> Name -> Name
max :: Name -> Name -> Name
$cmin :: Name -> Name -> Name
min :: Name -> Name -> Name
Ord, Typeable Name
Typeable Name =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Name -> c Name)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Name)
-> (Name -> Constr)
-> (Name -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Name))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name))
-> ((forall b. Data b => b -> b) -> Name -> Name)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r)
-> (forall u. (forall d. Data d => d -> u) -> Name -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Name -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Name -> m Name)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name)
-> Data Name
Name -> Constr
Name -> DataType
(forall b. Data b => b -> b) -> Name -> Name
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
forall u. (forall d. Data d => d -> u) -> Name -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Name -> m Name
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Name
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Name -> c Name
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Name)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Name -> c Name
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Name -> c Name
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Name
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Name
$ctoConstr :: Name -> Constr
toConstr :: Name -> Constr
$cdataTypeOf :: Name -> DataType
dataTypeOf :: Name -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Name)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Name)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
$cgmapT :: (forall b. Data b => b -> b) -> Name -> Name
gmapT :: (forall b. Data b => b -> b) -> Name -> Name
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Name -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Name -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Name -> m Name
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Name -> m Name
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Name -> m Name
Data, (forall x. Name -> Rep Name x)
-> (forall x. Rep Name x -> Name) -> Generic Name
forall x. Rep Name x -> Name
forall x. Name -> Rep Name x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Name -> Rep Name x
from :: forall x. Name -> Rep Name x
$cto :: forall x. Rep Name x -> Name
to :: forall x. Rep Name x -> Name
Generic, Typeable)

txt :: String -> T.Text
txt :: String -> Text
txt = String -> Text
T.pack

str :: T.Text -> String
str :: Text -> String
str = Text -> String
T.unpack

tnull :: T.Text -> Bool
tnull :: Text -> Bool
tnull = Text -> Bool
T.null

thead :: T.Text -> Char
thead :: Text -> Char
thead = HasCallStack => Text -> Char
Text -> Char
T.head

-- Smart constructors for names, using old String style
sUN :: String -> Name
sUN :: String -> Name
sUN String
s = Text -> Name
UN (String -> Text
txt String
s)

sNS :: Name -> [String] -> Name
sNS :: Name -> [String] -> Name
sNS Name
n [String]
ss = Name -> [Text] -> Name
NS Name
n ([Text] -> Name) -> [Text] -> Name
forall a b. NFData a => (a -> b) -> a -> b
$!! ((String -> Text) -> [String] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map String -> Text
txt [String]
ss)

sMN :: Int -> String -> Name
sMN :: Int -> String -> Name
sMN Int
i String
s = Int -> Text -> Name
MN Int
i (String -> Text
txt String
s)

caseName :: Name -> Bool
caseName (SN (CaseN FC'
_ Name
_)) = Bool
True
caseName (NS Name
n [Text]
_) = Name -> Bool
caseName Name
n
caseName Name
_ = Bool
False


{-!
deriving instance Binary Name
!-}

data SpecialName = WhereN !Int !Name !Name
                 | WithN !Int !Name
                 | ImplementationN !Name [T.Text]
                 | ParentN !Name !T.Text
                 | MethodN !Name
                 | CaseN !FC' !Name
                 | ImplementationCtorN !Name
                 | MetaN !Name !Name
  deriving (SpecialName -> SpecialName -> Bool
(SpecialName -> SpecialName -> Bool)
-> (SpecialName -> SpecialName -> Bool) -> Eq SpecialName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SpecialName -> SpecialName -> Bool
== :: SpecialName -> SpecialName -> Bool
$c/= :: SpecialName -> SpecialName -> Bool
/= :: SpecialName -> SpecialName -> Bool
Eq, Eq SpecialName
Eq SpecialName =>
(SpecialName -> SpecialName -> Ordering)
-> (SpecialName -> SpecialName -> Bool)
-> (SpecialName -> SpecialName -> Bool)
-> (SpecialName -> SpecialName -> Bool)
-> (SpecialName -> SpecialName -> Bool)
-> (SpecialName -> SpecialName -> SpecialName)
-> (SpecialName -> SpecialName -> SpecialName)
-> Ord SpecialName
SpecialName -> SpecialName -> Bool
SpecialName -> SpecialName -> Ordering
SpecialName -> SpecialName -> SpecialName
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SpecialName -> SpecialName -> Ordering
compare :: SpecialName -> SpecialName -> Ordering
$c< :: SpecialName -> SpecialName -> Bool
< :: SpecialName -> SpecialName -> Bool
$c<= :: SpecialName -> SpecialName -> Bool
<= :: SpecialName -> SpecialName -> Bool
$c> :: SpecialName -> SpecialName -> Bool
> :: SpecialName -> SpecialName -> Bool
$c>= :: SpecialName -> SpecialName -> Bool
>= :: SpecialName -> SpecialName -> Bool
$cmax :: SpecialName -> SpecialName -> SpecialName
max :: SpecialName -> SpecialName -> SpecialName
$cmin :: SpecialName -> SpecialName -> SpecialName
min :: SpecialName -> SpecialName -> SpecialName
Ord, Typeable SpecialName
Typeable SpecialName =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> SpecialName -> c SpecialName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SpecialName)
-> (SpecialName -> Constr)
-> (SpecialName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SpecialName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c SpecialName))
-> ((forall b. Data b => b -> b) -> SpecialName -> SpecialName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SpecialName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SpecialName -> r)
-> (forall u. (forall d. Data d => d -> u) -> SpecialName -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> SpecialName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SpecialName -> m SpecialName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SpecialName -> m SpecialName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SpecialName -> m SpecialName)
-> Data SpecialName
SpecialName -> Constr
SpecialName -> DataType
(forall b. Data b => b -> b) -> SpecialName -> SpecialName
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> SpecialName -> u
forall u. (forall d. Data d => d -> u) -> SpecialName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SpecialName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SpecialName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SpecialName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SpecialName -> c SpecialName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SpecialName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SpecialName)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SpecialName -> c SpecialName
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SpecialName -> c SpecialName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SpecialName
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SpecialName
$ctoConstr :: SpecialName -> Constr
toConstr :: SpecialName -> Constr
$cdataTypeOf :: SpecialName -> DataType
dataTypeOf :: SpecialName -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SpecialName)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SpecialName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SpecialName)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SpecialName)
$cgmapT :: (forall b. Data b => b -> b) -> SpecialName -> SpecialName
gmapT :: (forall b. Data b => b -> b) -> SpecialName -> SpecialName
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SpecialName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SpecialName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SpecialName -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SpecialName -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SpecialName -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> SpecialName -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SpecialName -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SpecialName -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecialName -> m SpecialName
Data, (forall x. SpecialName -> Rep SpecialName x)
-> (forall x. Rep SpecialName x -> SpecialName)
-> Generic SpecialName
forall x. Rep SpecialName x -> SpecialName
forall x. SpecialName -> Rep SpecialName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SpecialName -> Rep SpecialName x
from :: forall x. SpecialName -> Rep SpecialName x
$cto :: forall x. Rep SpecialName x -> SpecialName
to :: forall x. Rep SpecialName x -> SpecialName
Generic, Typeable)
{-!
deriving instance Binary SpecialName
!-}

sImplementationN :: Name -> [String] -> SpecialName
sImplementationN :: Name -> [String] -> SpecialName
sImplementationN Name
n [String]
ss = Name -> [Text] -> SpecialName
ImplementationN Name
n ((String -> Text) -> [String] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map String -> Text
T.pack [String]
ss)

instance Sized Name where
  size :: Name -> Int
size (UN Text
n)     = Int
1
  size (NS Name
n [Text]
els) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Text] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
els
  size (MN Int
i Text
n) = Int
1
  size Name
_ = Int
1

instance Pretty Name OutputAnnotation where
  pretty :: Name -> Doc OutputAnnotation
pretty n :: Name
n@(UN Text
n') = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Text -> String
T.unpack Text
n')
  pretty n :: Name
n@(NS Name
un [Text]
s) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
noAnnotate (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Name
un
  pretty n :: Name
n@(MN Int
i Text
s) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                      Doc OutputAnnotation
forall a. Doc a
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Text -> String
T.unpack Text
s) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Int -> String) -> Int -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> Doc OutputAnnotation) -> Int -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Int
i) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
rbrace
  pretty n :: Name
n@(SN SpecialName
s) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text (SpecialName -> String
forall a. Show a => a -> String
show SpecialName
s)
  pretty n :: Name
n@(SymRef Int
i) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                        String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation) -> String -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String
"##symbol" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"##"

instance Pretty [Name] OutputAnnotation where
  pretty :: [Name] -> Doc OutputAnnotation
pretty = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> [Doc a] -> Doc a
encloseSep Doc OutputAnnotation
forall a. Doc a
empty Doc OutputAnnotation
forall a. Doc a
empty Doc OutputAnnotation
forall a. Doc a
comma ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> ([Name] -> [Doc OutputAnnotation])
-> [Name]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name -> Doc OutputAnnotation) -> [Name] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty

instance Show Name where
    show :: Name -> String
show (UN Text
n) = Text -> String
str Text
n
    show (NS Name
n [Text]
s) = String -> [String] -> String
showSep String
"." ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack ([Text] -> [Text]
forall a. [a] -> [a]
reverse [Text]
s)) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
n
    show (MN Int
_ Text
u) | Text
u Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
txt String
"underscore" = String
"_"
    show (MN Int
i Text
s) = String
"{" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
str Text
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"}"
    show (SN SpecialName
s) = SpecialName -> String
forall a. Show a => a -> String
show SpecialName
s
    show (SymRef Int
i) = String
"##symbol" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"##"

instance Show SpecialName where
    show :: SpecialName -> String
show (WhereN Int
i Name
p Name
c) = Name -> String
forall a. Show a => a -> String
show Name
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
c
    show (WithN Int
i Name
n) = String
"with block in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
n
    show (ImplementationN Name
cl [Text]
impl) = String -> [String] -> String
showSep String
", " ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack [Text]
impl) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" implementation of " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
cl
    show (MethodN Name
m) = String
"method " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
m
    show (ParentN Name
p Text
c) = Name -> String
forall a. Show a => a -> String
show Name
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"#" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
c
    show (CaseN FC'
fc Name
n) = String
"case block in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
n String -> ShowS
forall a. [a] -> [a] -> [a]
++
                        if FC'
fc FC' -> FC' -> Bool
forall a. Eq a => a -> a -> Bool
== FC -> FC'
FC' FC
emptyFC then String
"" else String
" at " String -> ShowS
forall a. [a] -> [a] -> [a]
++ FC' -> String
forall a. Show a => a -> String
show FC'
fc
    show (ImplementationCtorN Name
n) = String
"constructor of " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
n
    show (MetaN Name
parent Name
meta) = String
"<<" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
parent String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
meta String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
">>"

-- Show a name in a way decorated for code generation, not human reading
showCG :: Name -> String
showCG :: Name -> String
showCG (UN Text
n) = Text -> String
T.unpack Text
n
showCG (NS Name
n [Text]
s) = String -> [String] -> String
showSep String
"." ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack ([Text] -> [Text]
forall a. [a] -> [a]
reverse [Text]
s)) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
showCG Name
n
showCG (MN Int
_ Text
u) | Text
u Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
txt String
"underscore" = String
"_"
showCG (MN Int
i Text
s) = String
"{" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"}"
showCG (SN SpecialName
s) = SpecialName -> String
showCG' SpecialName
s
  where showCG' :: SpecialName -> String
showCG' (WhereN Int
i Name
p Name
c) = Name -> String
showCG Name
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
showCG Name
c String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
        showCG' (WithN Int
i Name
n) = String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
showCG Name
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_with_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
        showCG' (ImplementationN Name
cl [Text]
impl) = Char
'@'Char -> ShowS
forall a. a -> [a] -> [a]
:Name -> String
showCG Name
cl String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char
'$'Char -> ShowS
forall a. a -> [a] -> [a]
:String -> [String] -> String
showSep String
":" ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack [Text]
impl)
        showCG' (MethodN Name
m) = Char
'!'Char -> ShowS
forall a. a -> [a] -> [a]
:Name -> String
showCG Name
m
        showCG' (ParentN Name
p Text
c) = Name -> String
showCG Name
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"#" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
c
        showCG' (CaseN FC'
fc Name
c) = Name -> String
showCG Name
c String -> ShowS
forall a. [a] -> [a] -> [a]
++ FC' -> String
showFC' FC'
fc String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_case"
        showCG' (ImplementationCtorN Name
n) = Name -> String
showCG Name
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_ictor"
        showCG' (MetaN Name
parent Name
meta) = Name -> String
showCG Name
parent String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_meta_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
showCG Name
meta
        showFC' :: FC' -> String
showFC' (FC' FC
NoFC) = String
""
        showFC' (FC' (FileFC String
f)) = String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
cgFN String
f
        showFC' (FC' (FC String
f (Int, Int)
s (Int, Int)
e))
          | (Int, Int)
s (Int, Int) -> (Int, Int) -> Bool
forall a. Eq a => a -> a -> Bool
== (Int, Int)
e = String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
cgFN String
f String -> ShowS
forall a. [a] -> [a] -> [a]
++
                     String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show ((Int, Int) -> Int
forall a b. (a, b) -> a
fst (Int, Int)
s) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show ((Int, Int) -> Int
forall a b. (a, b) -> b
snd (Int, Int)
s)
          | Bool
otherwise = String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
cgFN String
f String -> ShowS
forall a. [a] -> [a] -> [a]
++
                        String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show ((Int, Int) -> Int
forall a b. (a, b) -> a
fst (Int, Int)
s) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show ((Int, Int) -> Int
forall a b. (a, b) -> b
snd (Int, Int)
s) String -> ShowS
forall a. [a] -> [a] -> [a]
++
                        String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show ((Int, Int) -> Int
forall a b. (a, b) -> a
fst (Int, Int)
e) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show ((Int, Int) -> Int
forall a b. (a, b) -> b
snd (Int, Int)
e)
        cgFN :: ShowS
cgFN = (Char -> String) -> ShowS
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\Char
c -> if Bool -> Bool
not (Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char -> Bool
isLetter Char
c) then String
"__" else [Char
c])
showCG (SymRef Int
i) = ShowS
forall a. HasCallStack => String -> a
error String
"can't do codegen for a symbol reference"


-- |Contexts allow us to map names to things. A root name maps to a collection
-- of things in different namespaces with that name.
type Ctxt a = Map.Map Name (Map.Map Name a)
emptyContext :: Map k a
emptyContext = Map k a
forall k a. Map k a
Map.empty

mapCtxt :: (a -> b) -> Ctxt a -> Ctxt b
mapCtxt :: forall a b. (a -> b) -> Ctxt a -> Ctxt b
mapCtxt = (Map Name a -> Map Name b)
-> Map Name (Map Name a) -> Map Name (Map Name b)
forall a b. (a -> b) -> Map Name a -> Map Name b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Map Name a -> Map Name b)
 -> Map Name (Map Name a) -> Map Name (Map Name b))
-> ((a -> b) -> Map Name a -> Map Name b)
-> (a -> b)
-> Map Name (Map Name a)
-> Map Name (Map Name b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Map Name a -> Map Name b
forall a b. (a -> b) -> Map Name a -> Map Name b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

-- |Return True if the argument 'Name' should be interpreted as the name of a
-- interface.
tcname :: Name -> Bool
tcname (UN Text
xs) = Bool
False
tcname (NS Name
n [Text]
_) = Name -> Bool
tcname Name
n
tcname (SN (ImplementationN Name
_ [Text]
_)) = Bool
True
tcname (SN (MethodN Name
_)) = Bool
True
tcname (SN (ParentN Name
_ Text
_)) = Bool
True
tcname Name
_ = Bool
False

implicitable :: Name -> Bool
implicitable (NS Name
n [Text]
_) = Bool
False
implicitable (UN Text
xs) | Text -> Bool
T.null Text
xs = Bool
False
                     | Bool
otherwise = Char -> Bool
isLower (HasCallStack => Text -> Char
Text -> Char
T.head Text
xs) Bool -> Bool -> Bool
||
                                   HasCallStack => Text -> Char
Text -> Char
T.head Text
xs Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_'
implicitable (MN Int
_ Text
x) = Bool -> Bool
not (Text -> Bool
tnull Text
x) Bool -> Bool -> Bool
&& Text -> Char
thead Text
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'_'
implicitable Name
_ = Bool
False

nsroot :: Name -> Name
nsroot (NS Name
n [Text]
_) = Name
n
nsroot Name
n = Name
n

-- this will overwrite already existing definitions
addDef :: Name -> a -> Ctxt a -> Ctxt a
addDef :: forall a. Name -> a -> Ctxt a -> Ctxt a
addDef Name
n a
v Ctxt a
ctxt = case Name -> Ctxt a -> Maybe (Map Name a)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (Name -> Name
nsroot Name
n) Ctxt a
ctxt of
                        Maybe (Map Name a)
Nothing -> Name -> Map Name a -> Ctxt a -> Ctxt a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert (Name -> Name
nsroot Name
n)
                                        (Name -> a -> Map Name a -> Map Name a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Name
n a
v Map Name a
forall k a. Map k a
Map.empty) Ctxt a
ctxt
                        Just Map Name a
xs -> Name -> Map Name a -> Ctxt a -> Ctxt a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert (Name -> Name
nsroot Name
n)
                                        (Name -> a -> Map Name a -> Map Name a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Name
n a
v Map Name a
xs) Ctxt a
ctxt

{-| Look up a name in the context, given an optional namespace.
   The name (n) may itself have a (partial) namespace given.

   Rules for resolution:

    - if an explicit namespace is given, return the names which match it. If none
      match, return all names.

    - if the name has has explicit namespace given, return the names which match it
      and ignore the given namespace.

    - otherwise, return all names.

-}

lookupCtxtName :: Name -> Ctxt a -> [(Name, a)]
lookupCtxtName :: forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n Ctxt a
ctxt = case Name -> Ctxt a -> Maybe (Map Name a)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (Name -> Name
nsroot Name
n) Ctxt a
ctxt of
                                  Just Map Name a
xs -> [(Name, a)] -> [(Name, a)]
forall {b}. [(Name, b)] -> [(Name, b)]
filterNS (Map Name a -> [(Name, a)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Name a
xs)
                                  Maybe (Map Name a)
Nothing -> []
  where
    filterNS :: [(Name, b)] -> [(Name, b)]
filterNS [] = []
    filterNS ((Name
found, b
v) : [(Name, b)]
xs)
        | Name -> Name -> Bool
nsmatch Name
n Name
found = (Name
found, b
v) (Name, b) -> [(Name, b)] -> [(Name, b)]
forall a. a -> [a] -> [a]
: [(Name, b)] -> [(Name, b)]
filterNS [(Name, b)]
xs
        | Bool
otherwise       = [(Name, b)] -> [(Name, b)]
filterNS [(Name, b)]
xs

    nsmatch :: Name -> Name -> Bool
nsmatch (NS Name
n [Text]
ns) (NS Name
p [Text]
ps) = [Text]
ns [Text] -> [Text] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` [Text]
ps
    nsmatch (NS Name
_ [Text]
_)  Name
_         = Bool
False
    nsmatch Name
looking   Name
found     = Bool
True

lookupCtxt :: Name -> Ctxt a -> [a]
lookupCtxt :: forall a. Name -> Ctxt a -> [a]
lookupCtxt Name
n Ctxt a
ctxt = ((Name, a) -> a) -> [(Name, a)] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (Name, a) -> a
forall a b. (a, b) -> b
snd (Name -> Ctxt a -> [(Name, a)]
forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n Ctxt a
ctxt)

lookupCtxtExact :: Name -> Ctxt a -> Maybe a
lookupCtxtExact :: forall a. Name -> Ctxt a -> Maybe a
lookupCtxtExact Name
n Ctxt a
ctxt = [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe [ a
v | (Name
nm, a
v) <- Name -> Ctxt a -> [(Name, a)]
forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n Ctxt a
ctxt, Name
nm Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
n]

deleteDefExact :: Name -> Ctxt a -> Ctxt a
deleteDefExact :: forall a. Name -> Ctxt a -> Ctxt a
deleteDefExact Name
n = (Map Name a -> Map Name a)
-> Name -> Map Name (Map Name a) -> Map Name (Map Name a)
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust (Name -> Map Name a -> Map Name a
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete Name
n) (Name -> Name
nsroot Name
n)

updateDef :: Name -> (a -> a) -> Ctxt a -> Ctxt a
updateDef :: forall a. Name -> (a -> a) -> Ctxt a -> Ctxt a
updateDef Name
n a -> a
f Ctxt a
ctxt
  = case Name -> Ctxt a -> Maybe a
forall a. Name -> Ctxt a -> Maybe a
lookupCtxtExact Name
n Ctxt a
ctxt of
         Just a
t -> Name -> a -> Ctxt a -> Ctxt a
forall a. Name -> a -> Ctxt a -> Ctxt a
addDef Name
n (a -> a
f a
t) Ctxt a
ctxt
         Maybe a
Nothing -> Ctxt a
ctxt

toAlist :: Ctxt a -> [(Name, a)]
toAlist :: forall a. Ctxt a -> [(Name, a)]
toAlist Ctxt a
ctxt = let allns :: [Map Name a]
allns = ((Name, Map Name a) -> Map Name a)
-> [(Name, Map Name a)] -> [Map Name a]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Map Name a) -> Map Name a
forall a b. (a, b) -> b
snd (Ctxt a -> [(Name, Map Name a)]
forall k a. Map k a -> [(k, a)]
Map.toList Ctxt a
ctxt) in
                (Map Name a -> [(Name, a)]) -> [Map Name a] -> [(Name, a)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Map Name a -> [(Name, a)]
forall k a. Map k a -> [(k, a)]
Map.toList) [Map Name a]
allns

addAlist :: [(Name, a)] -> Ctxt a -> Ctxt a
addAlist :: forall a. [(Name, a)] -> Ctxt a -> Ctxt a
addAlist [] Ctxt a
ctxt = Ctxt a
ctxt
addAlist ((Name
n, a
tm) : [(Name, a)]
ds) Ctxt a
ctxt = Name -> a -> Ctxt a -> Ctxt a
forall a. Name -> a -> Ctxt a -> Ctxt a
addDef Name
n a
tm ([(Name, a)] -> Ctxt a -> Ctxt a
forall a. [(Name, a)] -> Ctxt a -> Ctxt a
addAlist [(Name, a)]
ds Ctxt a
ctxt)

data NativeTy = IT8 | IT16 | IT32 | IT64
    deriving (Int -> NativeTy -> ShowS
[NativeTy] -> ShowS
NativeTy -> String
(Int -> NativeTy -> ShowS)
-> (NativeTy -> String) -> ([NativeTy] -> ShowS) -> Show NativeTy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NativeTy -> ShowS
showsPrec :: Int -> NativeTy -> ShowS
$cshow :: NativeTy -> String
show :: NativeTy -> String
$cshowList :: [NativeTy] -> ShowS
showList :: [NativeTy] -> ShowS
Show, NativeTy -> NativeTy -> Bool
(NativeTy -> NativeTy -> Bool)
-> (NativeTy -> NativeTy -> Bool) -> Eq NativeTy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NativeTy -> NativeTy -> Bool
== :: NativeTy -> NativeTy -> Bool
$c/= :: NativeTy -> NativeTy -> Bool
/= :: NativeTy -> NativeTy -> Bool
Eq, Eq NativeTy
Eq NativeTy =>
(NativeTy -> NativeTy -> Ordering)
-> (NativeTy -> NativeTy -> Bool)
-> (NativeTy -> NativeTy -> Bool)
-> (NativeTy -> NativeTy -> Bool)
-> (NativeTy -> NativeTy -> Bool)
-> (NativeTy -> NativeTy -> NativeTy)
-> (NativeTy -> NativeTy -> NativeTy)
-> Ord NativeTy
NativeTy -> NativeTy -> Bool
NativeTy -> NativeTy -> Ordering
NativeTy -> NativeTy -> NativeTy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NativeTy -> NativeTy -> Ordering
compare :: NativeTy -> NativeTy -> Ordering
$c< :: NativeTy -> NativeTy -> Bool
< :: NativeTy -> NativeTy -> Bool
$c<= :: NativeTy -> NativeTy -> Bool
<= :: NativeTy -> NativeTy -> Bool
$c> :: NativeTy -> NativeTy -> Bool
> :: NativeTy -> NativeTy -> Bool
$c>= :: NativeTy -> NativeTy -> Bool
>= :: NativeTy -> NativeTy -> Bool
$cmax :: NativeTy -> NativeTy -> NativeTy
max :: NativeTy -> NativeTy -> NativeTy
$cmin :: NativeTy -> NativeTy -> NativeTy
min :: NativeTy -> NativeTy -> NativeTy
Ord, Int -> NativeTy
NativeTy -> Int
NativeTy -> [NativeTy]
NativeTy -> NativeTy
NativeTy -> NativeTy -> [NativeTy]
NativeTy -> NativeTy -> NativeTy -> [NativeTy]
(NativeTy -> NativeTy)
-> (NativeTy -> NativeTy)
-> (Int -> NativeTy)
-> (NativeTy -> Int)
-> (NativeTy -> [NativeTy])
-> (NativeTy -> NativeTy -> [NativeTy])
-> (NativeTy -> NativeTy -> [NativeTy])
-> (NativeTy -> NativeTy -> NativeTy -> [NativeTy])
-> Enum NativeTy
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: NativeTy -> NativeTy
succ :: NativeTy -> NativeTy
$cpred :: NativeTy -> NativeTy
pred :: NativeTy -> NativeTy
$ctoEnum :: Int -> NativeTy
toEnum :: Int -> NativeTy
$cfromEnum :: NativeTy -> Int
fromEnum :: NativeTy -> Int
$cenumFrom :: NativeTy -> [NativeTy]
enumFrom :: NativeTy -> [NativeTy]
$cenumFromThen :: NativeTy -> NativeTy -> [NativeTy]
enumFromThen :: NativeTy -> NativeTy -> [NativeTy]
$cenumFromTo :: NativeTy -> NativeTy -> [NativeTy]
enumFromTo :: NativeTy -> NativeTy -> [NativeTy]
$cenumFromThenTo :: NativeTy -> NativeTy -> NativeTy -> [NativeTy]
enumFromThenTo :: NativeTy -> NativeTy -> NativeTy -> [NativeTy]
Enum, Typeable NativeTy
Typeable NativeTy =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> NativeTy -> c NativeTy)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NativeTy)
-> (NativeTy -> Constr)
-> (NativeTy -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NativeTy))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NativeTy))
-> ((forall b. Data b => b -> b) -> NativeTy -> NativeTy)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NativeTy -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NativeTy -> r)
-> (forall u. (forall d. Data d => d -> u) -> NativeTy -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> NativeTy -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NativeTy -> m NativeTy)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NativeTy -> m NativeTy)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NativeTy -> m NativeTy)
-> Data NativeTy
NativeTy -> Constr
NativeTy -> DataType
(forall b. Data b => b -> b) -> NativeTy -> NativeTy
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NativeTy -> u
forall u. (forall d. Data d => d -> u) -> NativeTy -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NativeTy -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NativeTy -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NativeTy
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NativeTy -> c NativeTy
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NativeTy)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NativeTy)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NativeTy -> c NativeTy
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NativeTy -> c NativeTy
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NativeTy
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NativeTy
$ctoConstr :: NativeTy -> Constr
toConstr :: NativeTy -> Constr
$cdataTypeOf :: NativeTy -> DataType
dataTypeOf :: NativeTy -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NativeTy)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NativeTy)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NativeTy)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NativeTy)
$cgmapT :: (forall b. Data b => b -> b) -> NativeTy -> NativeTy
gmapT :: (forall b. Data b => b -> b) -> NativeTy -> NativeTy
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NativeTy -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NativeTy -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NativeTy -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NativeTy -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NativeTy -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NativeTy -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NativeTy -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NativeTy -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NativeTy -> m NativeTy
Data, (forall x. NativeTy -> Rep NativeTy x)
-> (forall x. Rep NativeTy x -> NativeTy) -> Generic NativeTy
forall x. Rep NativeTy x -> NativeTy
forall x. NativeTy -> Rep NativeTy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NativeTy -> Rep NativeTy x
from :: forall x. NativeTy -> Rep NativeTy x
$cto :: forall x. Rep NativeTy x -> NativeTy
to :: forall x. Rep NativeTy x -> NativeTy
Generic, Typeable)

instance Pretty NativeTy OutputAnnotation where
    pretty :: NativeTy -> Doc OutputAnnotation
pretty NativeTy
IT8  = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Bits8"
    pretty NativeTy
IT16 = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Bits16"
    pretty NativeTy
IT32 = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Bits32"
    pretty NativeTy
IT64 = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Bits64"

data IntTy = ITFixed NativeTy | ITNative | ITBig | ITChar
    deriving (Int -> IntTy -> ShowS
[IntTy] -> ShowS
IntTy -> String
(Int -> IntTy -> ShowS)
-> (IntTy -> String) -> ([IntTy] -> ShowS) -> Show IntTy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IntTy -> ShowS
showsPrec :: Int -> IntTy -> ShowS
$cshow :: IntTy -> String
show :: IntTy -> String
$cshowList :: [IntTy] -> ShowS
showList :: [IntTy] -> ShowS
Show, IntTy -> IntTy -> Bool
(IntTy -> IntTy -> Bool) -> (IntTy -> IntTy -> Bool) -> Eq IntTy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IntTy -> IntTy -> Bool
== :: IntTy -> IntTy -> Bool
$c/= :: IntTy -> IntTy -> Bool
/= :: IntTy -> IntTy -> Bool
Eq, Eq IntTy
Eq IntTy =>
(IntTy -> IntTy -> Ordering)
-> (IntTy -> IntTy -> Bool)
-> (IntTy -> IntTy -> Bool)
-> (IntTy -> IntTy -> Bool)
-> (IntTy -> IntTy -> Bool)
-> (IntTy -> IntTy -> IntTy)
-> (IntTy -> IntTy -> IntTy)
-> Ord IntTy
IntTy -> IntTy -> Bool
IntTy -> IntTy -> Ordering
IntTy -> IntTy -> IntTy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: IntTy -> IntTy -> Ordering
compare :: IntTy -> IntTy -> Ordering
$c< :: IntTy -> IntTy -> Bool
< :: IntTy -> IntTy -> Bool
$c<= :: IntTy -> IntTy -> Bool
<= :: IntTy -> IntTy -> Bool
$c> :: IntTy -> IntTy -> Bool
> :: IntTy -> IntTy -> Bool
$c>= :: IntTy -> IntTy -> Bool
>= :: IntTy -> IntTy -> Bool
$cmax :: IntTy -> IntTy -> IntTy
max :: IntTy -> IntTy -> IntTy
$cmin :: IntTy -> IntTy -> IntTy
min :: IntTy -> IntTy -> IntTy
Ord, Typeable IntTy
Typeable IntTy =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> IntTy -> c IntTy)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IntTy)
-> (IntTy -> Constr)
-> (IntTy -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c IntTy))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntTy))
-> ((forall b. Data b => b -> b) -> IntTy -> IntTy)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r)
-> (forall u. (forall d. Data d => d -> u) -> IntTy -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> IntTy -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> IntTy -> m IntTy)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IntTy -> m IntTy)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IntTy -> m IntTy)
-> Data IntTy
IntTy -> Constr
IntTy -> DataType
(forall b. Data b => b -> b) -> IntTy -> IntTy
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> IntTy -> u
forall u. (forall d. Data d => d -> u) -> IntTy -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IntTy
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IntTy -> c IntTy
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IntTy)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntTy)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IntTy -> c IntTy
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IntTy -> c IntTy
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IntTy
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IntTy
$ctoConstr :: IntTy -> Constr
toConstr :: IntTy -> Constr
$cdataTypeOf :: IntTy -> DataType
dataTypeOf :: IntTy -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IntTy)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IntTy)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntTy)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntTy)
$cgmapT :: (forall b. Data b => b -> b) -> IntTy -> IntTy
gmapT :: (forall b. Data b => b -> b) -> IntTy -> IntTy
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntTy -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> IntTy -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> IntTy -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IntTy -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IntTy -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IntTy -> m IntTy
Data, (forall x. IntTy -> Rep IntTy x)
-> (forall x. Rep IntTy x -> IntTy) -> Generic IntTy
forall x. Rep IntTy x -> IntTy
forall x. IntTy -> Rep IntTy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IntTy -> Rep IntTy x
from :: forall x. IntTy -> Rep IntTy x
$cto :: forall x. Rep IntTy x -> IntTy
to :: forall x. Rep IntTy x -> IntTy
Generic, Typeable)

intTyName :: IntTy -> String
intTyName :: IntTy -> String
intTyName IntTy
ITNative = String
"Int"
intTyName IntTy
ITBig = String
"BigInt"
intTyName (ITFixed NativeTy
sized) = String
"B" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (NativeTy -> Int
nativeTyWidth NativeTy
sized)
intTyName (IntTy
ITChar) = String
"Char"

data ArithTy = ATInt IntTy | ATFloat -- TODO: Float vectors https://github.com/idris-lang/Idris-dev/issues/1723
    deriving (Int -> ArithTy -> ShowS
[ArithTy] -> ShowS
ArithTy -> String
(Int -> ArithTy -> ShowS)
-> (ArithTy -> String) -> ([ArithTy] -> ShowS) -> Show ArithTy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ArithTy -> ShowS
showsPrec :: Int -> ArithTy -> ShowS
$cshow :: ArithTy -> String
show :: ArithTy -> String
$cshowList :: [ArithTy] -> ShowS
showList :: [ArithTy] -> ShowS
Show, ArithTy -> ArithTy -> Bool
(ArithTy -> ArithTy -> Bool)
-> (ArithTy -> ArithTy -> Bool) -> Eq ArithTy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ArithTy -> ArithTy -> Bool
== :: ArithTy -> ArithTy -> Bool
$c/= :: ArithTy -> ArithTy -> Bool
/= :: ArithTy -> ArithTy -> Bool
Eq, Eq ArithTy
Eq ArithTy =>
(ArithTy -> ArithTy -> Ordering)
-> (ArithTy -> ArithTy -> Bool)
-> (ArithTy -> ArithTy -> Bool)
-> (ArithTy -> ArithTy -> Bool)
-> (ArithTy -> ArithTy -> Bool)
-> (ArithTy -> ArithTy -> ArithTy)
-> (ArithTy -> ArithTy -> ArithTy)
-> Ord ArithTy
ArithTy -> ArithTy -> Bool
ArithTy -> ArithTy -> Ordering
ArithTy -> ArithTy -> ArithTy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ArithTy -> ArithTy -> Ordering
compare :: ArithTy -> ArithTy -> Ordering
$c< :: ArithTy -> ArithTy -> Bool
< :: ArithTy -> ArithTy -> Bool
$c<= :: ArithTy -> ArithTy -> Bool
<= :: ArithTy -> ArithTy -> Bool
$c> :: ArithTy -> ArithTy -> Bool
> :: ArithTy -> ArithTy -> Bool
$c>= :: ArithTy -> ArithTy -> Bool
>= :: ArithTy -> ArithTy -> Bool
$cmax :: ArithTy -> ArithTy -> ArithTy
max :: ArithTy -> ArithTy -> ArithTy
$cmin :: ArithTy -> ArithTy -> ArithTy
min :: ArithTy -> ArithTy -> ArithTy
Ord, Typeable ArithTy
Typeable ArithTy =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> ArithTy -> c ArithTy)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ArithTy)
-> (ArithTy -> Constr)
-> (ArithTy -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ArithTy))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArithTy))
-> ((forall b. Data b => b -> b) -> ArithTy -> ArithTy)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ArithTy -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ArithTy -> r)
-> (forall u. (forall d. Data d => d -> u) -> ArithTy -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ArithTy -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ArithTy -> m ArithTy)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArithTy -> m ArithTy)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArithTy -> m ArithTy)
-> Data ArithTy
ArithTy -> Constr
ArithTy -> DataType
(forall b. Data b => b -> b) -> ArithTy -> ArithTy
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ArithTy -> u
forall u. (forall d. Data d => d -> u) -> ArithTy -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArithTy -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArithTy -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArithTy
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArithTy -> c ArithTy
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArithTy)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArithTy)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArithTy -> c ArithTy
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArithTy -> c ArithTy
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArithTy
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArithTy
$ctoConstr :: ArithTy -> Constr
toConstr :: ArithTy -> Constr
$cdataTypeOf :: ArithTy -> DataType
dataTypeOf :: ArithTy -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArithTy)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArithTy)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArithTy)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArithTy)
$cgmapT :: (forall b. Data b => b -> b) -> ArithTy -> ArithTy
gmapT :: (forall b. Data b => b -> b) -> ArithTy -> ArithTy
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArithTy -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArithTy -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArithTy -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArithTy -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ArithTy -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ArithTy -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArithTy -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArithTy -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArithTy -> m ArithTy
Data, (forall x. ArithTy -> Rep ArithTy x)
-> (forall x. Rep ArithTy x -> ArithTy) -> Generic ArithTy
forall x. Rep ArithTy x -> ArithTy
forall x. ArithTy -> Rep ArithTy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ArithTy -> Rep ArithTy x
from :: forall x. ArithTy -> Rep ArithTy x
$cto :: forall x. Rep ArithTy x -> ArithTy
to :: forall x. Rep ArithTy x -> ArithTy
Generic, Typeable)

instance Pretty ArithTy OutputAnnotation where
    pretty :: ArithTy -> Doc OutputAnnotation
pretty (ATInt IntTy
ITNative) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Int"
    pretty (ATInt IntTy
ITBig) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"BigInt"
    pretty (ATInt IntTy
ITChar) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Char"
    pretty (ATInt (ITFixed NativeTy
n)) = NativeTy -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty NativeTy
n
    pretty ArithTy
ATFloat = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Float"

nativeTyWidth :: NativeTy -> Int
nativeTyWidth :: NativeTy -> Int
nativeTyWidth NativeTy
IT8 = Int
8
nativeTyWidth NativeTy
IT16 = Int
16
nativeTyWidth NativeTy
IT32 = Int
32
nativeTyWidth NativeTy
IT64 = Int
64

data Const = I Int | BI Integer | Fl Double | Ch Char | Str String
           | B8 Word8 | B16 Word16 | B32 Word32 | B64 Word64
           | AType ArithTy | StrType
           | WorldType | TheWorld
           | VoidType | Forgot
  deriving (Eq Const
Eq Const =>
(Const -> Const -> Ordering)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Const)
-> (Const -> Const -> Const)
-> Ord Const
Const -> Const -> Bool
Const -> Const -> Ordering
Const -> Const -> Const
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Const -> Const -> Ordering
compare :: Const -> Const -> Ordering
$c< :: Const -> Const -> Bool
< :: Const -> Const -> Bool
$c<= :: Const -> Const -> Bool
<= :: Const -> Const -> Bool
$c> :: Const -> Const -> Bool
> :: Const -> Const -> Bool
$c>= :: Const -> Const -> Bool
>= :: Const -> Const -> Bool
$cmax :: Const -> Const -> Const
max :: Const -> Const -> Const
$cmin :: Const -> Const -> Const
min :: Const -> Const -> Const
Ord, Typeable Const
Typeable Const =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Const -> c Const)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Const)
-> (Const -> Constr)
-> (Const -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Const))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const))
-> ((forall b. Data b => b -> b) -> Const -> Const)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r)
-> (forall u. (forall d. Data d => d -> u) -> Const -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Const -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Const -> m Const)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Const -> m Const)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Const -> m Const)
-> Data Const
Const -> Constr
Const -> DataType
(forall b. Data b => b -> b) -> Const -> Const
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Const -> u
forall u. (forall d. Data d => d -> u) -> Const -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Const -> m Const
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Const
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Const -> c Const
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Const)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Const -> c Const
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Const -> c Const
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Const
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Const
$ctoConstr :: Const -> Constr
toConstr :: Const -> Constr
$cdataTypeOf :: Const -> DataType
dataTypeOf :: Const -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Const)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Const)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const)
$cgmapT :: (forall b. Data b => b -> b) -> Const -> Const
gmapT :: (forall b. Data b => b -> b) -> Const -> Const
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Const -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Const -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Const -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Const -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Const -> m Const
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Const -> m Const
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
Data, (forall x. Const -> Rep Const x)
-> (forall x. Rep Const x -> Const) -> Generic Const
forall x. Rep Const x -> Const
forall x. Const -> Rep Const x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Const -> Rep Const x
from :: forall x. Const -> Rep Const x
$cto :: forall x. Rep Const x -> Const
to :: forall x. Rep Const x -> Const
Generic, Typeable)

-- We need to compare Double using bit-pattern identity rather than
-- Haskell's Eq, which equates 0.0 and -0.0, leading to a
-- contradiction in the type theory. Bit-pattern identity will also
-- avoid similar problems for NaNs.
instance Eq Const where
  I Int
i       == :: Const -> Const -> Bool
== I Int
j       = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
j
  BI Integer
i      == BI Integer
j      = Integer
i Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
j
  Fl Double
i      == Fl Double
j      = Double -> Double -> Bool
forall a. IEEE a => a -> a -> Bool
identicalIEEE Double
i Double
j
  Ch Char
i      == Ch Char
j      = Char
i Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
j
  Str String
i     == Str String
j     = String
i String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
j
  B8 Word8
i      == B8 Word8
j      = Word8
i Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
j
  B16 Word16
i     == B16 Word16
j     = Word16
i Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
j
  B32 Word32
i     == B32 Word32
j     = Word32
i Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
j
  B64 Word64
i     == B64 Word64
j     = Word64
i Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
j
  AType ArithTy
i   == AType ArithTy
j   = ArithTy
i ArithTy -> ArithTy -> Bool
forall a. Eq a => a -> a -> Bool
== ArithTy
j
  Const
StrType   == Const
StrType   = Bool
True
  Const
WorldType == Const
WorldType = Bool
True
  Const
TheWorld  == Const
TheWorld  = Bool
True
  Const
VoidType  == Const
VoidType  = Bool
True
  Const
Forgot    == Const
Forgot    = Bool
True
  Const
_         == Const
_         = Bool
False

{-!
deriving instance Binary Const
!-}

isTypeConst :: Const -> Bool
isTypeConst :: Const -> Bool
isTypeConst (AType ArithTy
_) = Bool
True
isTypeConst Const
StrType = Bool
True
isTypeConst Const
WorldType = Bool
True
isTypeConst Const
VoidType = Bool
True
isTypeConst Const
_ = Bool
False

instance Sized Const where
  size :: Const -> Int
size Const
_ = Int
1

instance Pretty Const OutputAnnotation where
  pretty :: Const -> Doc OutputAnnotation
pretty (I Int
i) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Int -> String) -> Int -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> Doc OutputAnnotation) -> Int -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Int
i
  pretty (BI Integer
i) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Integer -> String) -> Integer -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show (Integer -> Doc OutputAnnotation)
-> Integer -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Integer
i
  pretty (Fl Double
f) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Double -> String) -> Double -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> String
forall a. Show a => a -> String
show (Double -> Doc OutputAnnotation) -> Double -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Double
f
  pretty (Ch Char
c) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Char -> String) -> Char -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> String
forall a. Show a => a -> String
show (Char -> Doc OutputAnnotation) -> Char -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Char
c
  pretty (Str String
s) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
s
  pretty (AType ArithTy
a) = ArithTy -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty ArithTy
a
  pretty Const
StrType = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"String"
  pretty Const
TheWorld = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"%theWorld"
  pretty Const
WorldType = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"prim__World"
  pretty Const
VoidType = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Void"
  pretty Const
Forgot = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Forgot"
  pretty (B8 Word8
w) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Word8 -> String) -> Word8 -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> String
forall a. Show a => a -> String
show (Word8 -> Doc OutputAnnotation) -> Word8 -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Word8
w
  pretty (B16 Word16
w) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Word16 -> String) -> Word16 -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> String
forall a. Show a => a -> String
show (Word16 -> Doc OutputAnnotation) -> Word16 -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Word16
w
  pretty (B32 Word32
w) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Word32 -> String) -> Word32 -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> String
forall a. Show a => a -> String
show (Word32 -> Doc OutputAnnotation) -> Word32 -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Word32
w
  pretty (B64 Word64
w) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Word64 -> String) -> Word64 -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> String
forall a. Show a => a -> String
show (Word64 -> Doc OutputAnnotation) -> Word64 -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Word64
w

-- | Determines whether the input constant represents a type
constIsType :: Const -> Bool
constIsType :: Const -> Bool
constIsType (I Int
_) = Bool
False
constIsType (BI Integer
_) = Bool
False
constIsType (Fl Double
_) = Bool
False
constIsType (Ch Char
_) = Bool
False
constIsType (Str String
_) = Bool
False
constIsType (B8 Word8
_) = Bool
False
constIsType (B16 Word16
_) = Bool
False
constIsType (B32 Word32
_) = Bool
False
constIsType (B64 Word64
_) = Bool
False
constIsType Const
_ = Bool
True

-- | Get the docstring for a Const
constDocs :: Const -> String
constDocs :: Const -> String
constDocs c :: Const
c@(AType (ATInt IntTy
ITBig))          = String
"Arbitrary-precision integers"
constDocs c :: Const
c@(AType (ATInt IntTy
ITNative))       = String
"Fixed-precision integers of undefined size"
constDocs c :: Const
c@(AType (ATInt IntTy
ITChar))         = String
"Characters in some unspecified encoding"
constDocs c :: Const
c@(AType ArithTy
ATFloat)                = String
"Double-precision floating-point numbers"
constDocs Const
StrType                          = String
"Strings in some unspecified encoding"
constDocs c :: Const
c@(AType (ATInt (ITFixed NativeTy
IT8)))  = String
"Eight bits (unsigned)"
constDocs c :: Const
c@(AType (ATInt (ITFixed NativeTy
IT16))) = String
"Sixteen bits (unsigned)"
constDocs c :: Const
c@(AType (ATInt (ITFixed NativeTy
IT32))) = String
"Thirty-two bits (unsigned)"
constDocs c :: Const
c@(AType (ATInt (ITFixed NativeTy
IT64))) = String
"Sixty-four bits (unsigned)"
constDocs (Fl Double
f)                           = String
"A float"
constDocs (I Int
i)                            = String
"A fixed-precision integer"
constDocs (BI Integer
i)                           = String
"An arbitrary-precision integer"
constDocs (Str String
s)                          = String
"A string of length " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s)
constDocs (Ch Char
c)                           = String
"A character"
constDocs (B8 Word8
w)                           = String
"The eight-bit value 0x" String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                             Word8 -> (Int -> Char) -> Word8 -> ShowS
forall a. Integral a => a -> (Int -> Char) -> a -> ShowS
showIntAtBase Word8
16 Int -> Char
intToDigit Word8
w String
""
constDocs (B16 Word16
w)                          = String
"The sixteen-bit value 0x" String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                             Word16 -> (Int -> Char) -> Word16 -> ShowS
forall a. Integral a => a -> (Int -> Char) -> a -> ShowS
showIntAtBase Word16
16 Int -> Char
intToDigit Word16
w String
""
constDocs (B32 Word32
w)                          = String
"The thirty-two-bit value 0x" String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                             Word32 -> (Int -> Char) -> Word32 -> ShowS
forall a. Integral a => a -> (Int -> Char) -> a -> ShowS
showIntAtBase Word32
16 Int -> Char
intToDigit Word32
w String
""
constDocs (B64 Word64
w)                          = String
"The sixty-four-bit value 0x" String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                             Word64 -> (Int -> Char) -> Word64 -> ShowS
forall a. Integral a => a -> (Int -> Char) -> a -> ShowS
showIntAtBase Word64
16 Int -> Char
intToDigit Word64
w String
""
constDocs Const
prim                             = String
"Undocumented"

data Universe = NullType | UniqueType | AllTypes
  deriving (Universe -> Universe -> Bool
(Universe -> Universe -> Bool)
-> (Universe -> Universe -> Bool) -> Eq Universe
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Universe -> Universe -> Bool
== :: Universe -> Universe -> Bool
$c/= :: Universe -> Universe -> Bool
/= :: Universe -> Universe -> Bool
Eq, Eq Universe
Eq Universe =>
(Universe -> Universe -> Ordering)
-> (Universe -> Universe -> Bool)
-> (Universe -> Universe -> Bool)
-> (Universe -> Universe -> Bool)
-> (Universe -> Universe -> Bool)
-> (Universe -> Universe -> Universe)
-> (Universe -> Universe -> Universe)
-> Ord Universe
Universe -> Universe -> Bool
Universe -> Universe -> Ordering
Universe -> Universe -> Universe
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Universe -> Universe -> Ordering
compare :: Universe -> Universe -> Ordering
$c< :: Universe -> Universe -> Bool
< :: Universe -> Universe -> Bool
$c<= :: Universe -> Universe -> Bool
<= :: Universe -> Universe -> Bool
$c> :: Universe -> Universe -> Bool
> :: Universe -> Universe -> Bool
$c>= :: Universe -> Universe -> Bool
>= :: Universe -> Universe -> Bool
$cmax :: Universe -> Universe -> Universe
max :: Universe -> Universe -> Universe
$cmin :: Universe -> Universe -> Universe
min :: Universe -> Universe -> Universe
Ord, Typeable Universe
Typeable Universe =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Universe -> c Universe)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Universe)
-> (Universe -> Constr)
-> (Universe -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Universe))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Universe))
-> ((forall b. Data b => b -> b) -> Universe -> Universe)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Universe -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Universe -> r)
-> (forall u. (forall d. Data d => d -> u) -> Universe -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Universe -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Universe -> m Universe)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Universe -> m Universe)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Universe -> m Universe)
-> Data Universe
Universe -> Constr
Universe -> DataType
(forall b. Data b => b -> b) -> Universe -> Universe
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Universe -> u
forall u. (forall d. Data d => d -> u) -> Universe -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Universe -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Universe -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Universe
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Universe -> c Universe
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Universe)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Universe)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Universe -> c Universe
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Universe -> c Universe
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Universe
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Universe
$ctoConstr :: Universe -> Constr
toConstr :: Universe -> Constr
$cdataTypeOf :: Universe -> DataType
dataTypeOf :: Universe -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Universe)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Universe)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Universe)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Universe)
$cgmapT :: (forall b. Data b => b -> b) -> Universe -> Universe
gmapT :: (forall b. Data b => b -> b) -> Universe -> Universe
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Universe -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Universe -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Universe -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Universe -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Universe -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Universe -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Universe -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Universe -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Universe -> m Universe
Data, (forall x. Universe -> Rep Universe x)
-> (forall x. Rep Universe x -> Universe) -> Generic Universe
forall x. Rep Universe x -> Universe
forall x. Universe -> Rep Universe x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Universe -> Rep Universe x
from :: forall x. Universe -> Rep Universe x
$cto :: forall x. Rep Universe x -> Universe
to :: forall x. Rep Universe x -> Universe
Generic, Typeable)

instance Show Universe where
    show :: Universe -> String
show Universe
UniqueType = String
"UniqueType"
    show Universe
NullType = String
"NullType"
    show Universe
AllTypes = String
"AnyType"

data Raw = Var Name
         | RBind Name (Binder Raw) Raw
         | RApp Raw Raw
         | RType
         | RUType Universe
         | RConstant Const
  deriving (Int -> Raw -> ShowS
[Raw] -> ShowS
Raw -> String
(Int -> Raw -> ShowS)
-> (Raw -> String) -> ([Raw] -> ShowS) -> Show Raw
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Raw -> ShowS
showsPrec :: Int -> Raw -> ShowS
$cshow :: Raw -> String
show :: Raw -> String
$cshowList :: [Raw] -> ShowS
showList :: [Raw] -> ShowS
Show, Raw -> Raw -> Bool
(Raw -> Raw -> Bool) -> (Raw -> Raw -> Bool) -> Eq Raw
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Raw -> Raw -> Bool
== :: Raw -> Raw -> Bool
$c/= :: Raw -> Raw -> Bool
/= :: Raw -> Raw -> Bool
Eq, Eq Raw
Eq Raw =>
(Raw -> Raw -> Ordering)
-> (Raw -> Raw -> Bool)
-> (Raw -> Raw -> Bool)
-> (Raw -> Raw -> Bool)
-> (Raw -> Raw -> Bool)
-> (Raw -> Raw -> Raw)
-> (Raw -> Raw -> Raw)
-> Ord Raw
Raw -> Raw -> Bool
Raw -> Raw -> Ordering
Raw -> Raw -> Raw
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Raw -> Raw -> Ordering
compare :: Raw -> Raw -> Ordering
$c< :: Raw -> Raw -> Bool
< :: Raw -> Raw -> Bool
$c<= :: Raw -> Raw -> Bool
<= :: Raw -> Raw -> Bool
$c> :: Raw -> Raw -> Bool
> :: Raw -> Raw -> Bool
$c>= :: Raw -> Raw -> Bool
>= :: Raw -> Raw -> Bool
$cmax :: Raw -> Raw -> Raw
max :: Raw -> Raw -> Raw
$cmin :: Raw -> Raw -> Raw
min :: Raw -> Raw -> Raw
Ord, Typeable Raw
Typeable Raw =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Raw -> c Raw)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Raw)
-> (Raw -> Constr)
-> (Raw -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Raw))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Raw))
-> ((forall b. Data b => b -> b) -> Raw -> Raw)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r)
-> (forall u. (forall d. Data d => d -> u) -> Raw -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Raw -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Raw -> m Raw)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Raw -> m Raw)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Raw -> m Raw)
-> Data Raw
Raw -> Constr
Raw -> DataType
(forall b. Data b => b -> b) -> Raw -> Raw
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Raw -> u
forall u. (forall d. Data d => d -> u) -> Raw -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Raw
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Raw -> c Raw
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Raw)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Raw)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Raw -> c Raw
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Raw -> c Raw
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Raw
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Raw
$ctoConstr :: Raw -> Constr
toConstr :: Raw -> Constr
$cdataTypeOf :: Raw -> DataType
dataTypeOf :: Raw -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Raw)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Raw)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Raw)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Raw)
$cgmapT :: (forall b. Data b => b -> b) -> Raw -> Raw
gmapT :: (forall b. Data b => b -> b) -> Raw -> Raw
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Raw -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Raw -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Raw -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Raw -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Raw -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Raw -> m Raw
Data, (forall x. Raw -> Rep Raw x)
-> (forall x. Rep Raw x -> Raw) -> Generic Raw
forall x. Rep Raw x -> Raw
forall x. Raw -> Rep Raw x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Raw -> Rep Raw x
from :: forall x. Raw -> Rep Raw x
$cto :: forall x. Rep Raw x -> Raw
to :: forall x. Rep Raw x -> Raw
Generic, Typeable)

instance Sized Raw where
  size :: Raw -> Int
size (Var Name
name) = Int
1
  size (RBind Name
name Binder Raw
bind Raw
right) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Binder Raw -> Int
forall a. Sized a => a -> Int
size Binder Raw
bind Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Raw -> Int
forall a. Sized a => a -> Int
size Raw
right
  size (RApp Raw
left Raw
right) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Raw -> Int
forall a. Sized a => a -> Int
size Raw
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Raw -> Int
forall a. Sized a => a -> Int
size Raw
right
  size Raw
RType = Int
1
  size (RUType Universe
_) = Int
1
  size (RConstant Const
const) = Const -> Int
forall a. Sized a => a -> Int
size Const
const

instance Pretty Raw OutputAnnotation where
  pretty :: Raw -> Doc OutputAnnotation
pretty = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (Raw -> String) -> Raw -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Raw -> String
forall a. Show a => a -> String
show

{-!
deriving instance Binary Raw
!-}

data ImplicitInfo = Impl { ImplicitInfo -> Bool
tcimplementation :: Bool, ImplicitInfo -> Bool
toplevel_imp :: Bool,
                           ImplicitInfo -> Bool
machine_gen :: Bool }
  deriving (Int -> ImplicitInfo -> ShowS
[ImplicitInfo] -> ShowS
ImplicitInfo -> String
(Int -> ImplicitInfo -> ShowS)
-> (ImplicitInfo -> String)
-> ([ImplicitInfo] -> ShowS)
-> Show ImplicitInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImplicitInfo -> ShowS
showsPrec :: Int -> ImplicitInfo -> ShowS
$cshow :: ImplicitInfo -> String
show :: ImplicitInfo -> String
$cshowList :: [ImplicitInfo] -> ShowS
showList :: [ImplicitInfo] -> ShowS
Show, ImplicitInfo -> ImplicitInfo -> Bool
(ImplicitInfo -> ImplicitInfo -> Bool)
-> (ImplicitInfo -> ImplicitInfo -> Bool) -> Eq ImplicitInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImplicitInfo -> ImplicitInfo -> Bool
== :: ImplicitInfo -> ImplicitInfo -> Bool
$c/= :: ImplicitInfo -> ImplicitInfo -> Bool
/= :: ImplicitInfo -> ImplicitInfo -> Bool
Eq, Eq ImplicitInfo
Eq ImplicitInfo =>
(ImplicitInfo -> ImplicitInfo -> Ordering)
-> (ImplicitInfo -> ImplicitInfo -> Bool)
-> (ImplicitInfo -> ImplicitInfo -> Bool)
-> (ImplicitInfo -> ImplicitInfo -> Bool)
-> (ImplicitInfo -> ImplicitInfo -> Bool)
-> (ImplicitInfo -> ImplicitInfo -> ImplicitInfo)
-> (ImplicitInfo -> ImplicitInfo -> ImplicitInfo)
-> Ord ImplicitInfo
ImplicitInfo -> ImplicitInfo -> Bool
ImplicitInfo -> ImplicitInfo -> Ordering
ImplicitInfo -> ImplicitInfo -> ImplicitInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ImplicitInfo -> ImplicitInfo -> Ordering
compare :: ImplicitInfo -> ImplicitInfo -> Ordering
$c< :: ImplicitInfo -> ImplicitInfo -> Bool
< :: ImplicitInfo -> ImplicitInfo -> Bool
$c<= :: ImplicitInfo -> ImplicitInfo -> Bool
<= :: ImplicitInfo -> ImplicitInfo -> Bool
$c> :: ImplicitInfo -> ImplicitInfo -> Bool
> :: ImplicitInfo -> ImplicitInfo -> Bool
$c>= :: ImplicitInfo -> ImplicitInfo -> Bool
>= :: ImplicitInfo -> ImplicitInfo -> Bool
$cmax :: ImplicitInfo -> ImplicitInfo -> ImplicitInfo
max :: ImplicitInfo -> ImplicitInfo -> ImplicitInfo
$cmin :: ImplicitInfo -> ImplicitInfo -> ImplicitInfo
min :: ImplicitInfo -> ImplicitInfo -> ImplicitInfo
Ord, Typeable ImplicitInfo
Typeable ImplicitInfo =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> ImplicitInfo -> c ImplicitInfo)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ImplicitInfo)
-> (ImplicitInfo -> Constr)
-> (ImplicitInfo -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ImplicitInfo))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ImplicitInfo))
-> ((forall b. Data b => b -> b) -> ImplicitInfo -> ImplicitInfo)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r)
-> (forall u. (forall d. Data d => d -> u) -> ImplicitInfo -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ImplicitInfo -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo)
-> Data ImplicitInfo
ImplicitInfo -> Constr
ImplicitInfo -> DataType
(forall b. Data b => b -> b) -> ImplicitInfo -> ImplicitInfo
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ImplicitInfo -> u
forall u. (forall d. Data d => d -> u) -> ImplicitInfo -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ImplicitInfo
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ImplicitInfo -> c ImplicitInfo
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ImplicitInfo)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ImplicitInfo)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ImplicitInfo -> c ImplicitInfo
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ImplicitInfo -> c ImplicitInfo
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ImplicitInfo
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ImplicitInfo
$ctoConstr :: ImplicitInfo -> Constr
toConstr :: ImplicitInfo -> Constr
$cdataTypeOf :: ImplicitInfo -> DataType
dataTypeOf :: ImplicitInfo -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ImplicitInfo)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ImplicitInfo)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ImplicitInfo)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ImplicitInfo)
$cgmapT :: (forall b. Data b => b -> b) -> ImplicitInfo -> ImplicitInfo
gmapT :: (forall b. Data b => b -> b) -> ImplicitInfo -> ImplicitInfo
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ImplicitInfo -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ImplicitInfo -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ImplicitInfo -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ImplicitInfo -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ImplicitInfo -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ImplicitInfo -> m ImplicitInfo
Data, (forall x. ImplicitInfo -> Rep ImplicitInfo x)
-> (forall x. Rep ImplicitInfo x -> ImplicitInfo)
-> Generic ImplicitInfo
forall x. Rep ImplicitInfo x -> ImplicitInfo
forall x. ImplicitInfo -> Rep ImplicitInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ImplicitInfo -> Rep ImplicitInfo x
from :: forall x. ImplicitInfo -> Rep ImplicitInfo x
$cto :: forall x. Rep ImplicitInfo x -> ImplicitInfo
to :: forall x. Rep ImplicitInfo x -> ImplicitInfo
Generic, Typeable)

{-!
deriving instance Binary ImplicitInfo
!-}

-- The type parameter `b` will normally be something like `TT Name` or just
-- `Raw`. We do not make a type-level distinction between TT terms that happen
-- to be TT types and TT terms that are not TT types.
-- | All binding forms are represented in a uniform fashion. This type only represents
-- the types of bindings (and their values, if any); the attached identifiers are part
-- of the 'Bind' constructor for the 'TT' type.
data Binder b = Lam   { forall b. Binder b -> RigCount
binderCount :: RigCount,
                        forall b. Binder b -> b
binderTy  :: !b {-^ type annotation for bound variable-}}
                -- ^ A function binding
              | Pi    { binderCount :: RigCount,
                        forall b. Binder b -> Maybe ImplicitInfo
binderImpl :: Maybe ImplicitInfo,
                        binderTy  :: !b,
                        forall b. Binder b -> b
binderKind :: !b }
                -- ^ A binding that occurs in a function type
                -- expression, e.g. @(x:Int) -> ...@ The 'binderImpl'
                -- flag says whether it was a scoped implicit
                -- (i.e. forall bound) in the high level Idris, but
                -- otherwise has no relevance in TT.
              | Let   { binderCount :: RigCount,
                        binderTy  :: !b,
                        forall b. Binder b -> b
binderVal :: b {-^ value for bound variable-}}
                -- ^ A binding that occurs in a @let@ expression
              | NLet  { binderTy  :: !b,
                        binderVal :: b }
                -- ^ NLet is an intermediate product in the evaluator
                -- that's used for temporarily naming locals during
                -- reduction. It won't occur outside the evaluator.
              | Hole  { binderTy  :: !b}
                -- ^ A hole in a term under construction in the
                -- elaborator. If this is not filled during
                -- elaboration, it is an error.
              | GHole { forall b. Binder b -> Int
envlen :: Int,
                        forall b. Binder b -> [Name]
localnames :: [Name],
                        binderTy  :: !b}
                -- ^ A saved TT hole that will later be converted to a
                -- top-level Idris metavariable applied to all
                -- elements of its local environment.
              | Guess { binderTy  :: !b,
                        binderVal :: b }
                -- ^ A provided value for a hole. It will later be
                -- substituted - the guess is to keep it
                -- computationally inert while working on other things
                -- if necessary.
              | PVar  { binderCount :: RigCount,
                        binderTy  :: !b }
                -- ^ A pattern variable (these are bound around terms
                -- that make up pattern-match clauses)
              | PVTy  { binderTy  :: !b }
                -- ^ The type of a pattern binding
  deriving (Int -> Binder b -> ShowS
[Binder b] -> ShowS
Binder b -> String
(Int -> Binder b -> ShowS)
-> (Binder b -> String) -> ([Binder b] -> ShowS) -> Show (Binder b)
forall b. Show b => Int -> Binder b -> ShowS
forall b. Show b => [Binder b] -> ShowS
forall b. Show b => Binder b -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall b. Show b => Int -> Binder b -> ShowS
showsPrec :: Int -> Binder b -> ShowS
$cshow :: forall b. Show b => Binder b -> String
show :: Binder b -> String
$cshowList :: forall b. Show b => [Binder b] -> ShowS
showList :: [Binder b] -> ShowS
Show, Binder b -> Binder b -> Bool
(Binder b -> Binder b -> Bool)
-> (Binder b -> Binder b -> Bool) -> Eq (Binder b)
forall b. Eq b => Binder b -> Binder b -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall b. Eq b => Binder b -> Binder b -> Bool
== :: Binder b -> Binder b -> Bool
$c/= :: forall b. Eq b => Binder b -> Binder b -> Bool
/= :: Binder b -> Binder b -> Bool
Eq, Eq (Binder b)
Eq (Binder b) =>
(Binder b -> Binder b -> Ordering)
-> (Binder b -> Binder b -> Bool)
-> (Binder b -> Binder b -> Bool)
-> (Binder b -> Binder b -> Bool)
-> (Binder b -> Binder b -> Bool)
-> (Binder b -> Binder b -> Binder b)
-> (Binder b -> Binder b -> Binder b)
-> Ord (Binder b)
Binder b -> Binder b -> Bool
Binder b -> Binder b -> Ordering
Binder b -> Binder b -> Binder b
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall b. Ord b => Eq (Binder b)
forall b. Ord b => Binder b -> Binder b -> Bool
forall b. Ord b => Binder b -> Binder b -> Ordering
forall b. Ord b => Binder b -> Binder b -> Binder b
$ccompare :: forall b. Ord b => Binder b -> Binder b -> Ordering
compare :: Binder b -> Binder b -> Ordering
$c< :: forall b. Ord b => Binder b -> Binder b -> Bool
< :: Binder b -> Binder b -> Bool
$c<= :: forall b. Ord b => Binder b -> Binder b -> Bool
<= :: Binder b -> Binder b -> Bool
$c> :: forall b. Ord b => Binder b -> Binder b -> Bool
> :: Binder b -> Binder b -> Bool
$c>= :: forall b. Ord b => Binder b -> Binder b -> Bool
>= :: Binder b -> Binder b -> Bool
$cmax :: forall b. Ord b => Binder b -> Binder b -> Binder b
max :: Binder b -> Binder b -> Binder b
$cmin :: forall b. Ord b => Binder b -> Binder b -> Binder b
min :: Binder b -> Binder b -> Binder b
Ord, (forall a b. (a -> b) -> Binder a -> Binder b)
-> (forall a b. a -> Binder b -> Binder a) -> Functor Binder
forall a b. a -> Binder b -> Binder a
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Binder a -> Binder b
fmap :: forall a b. (a -> b) -> Binder a -> Binder b
$c<$ :: forall a b. a -> Binder b -> Binder a
<$ :: forall a b. a -> Binder b -> Binder a
Functor, (forall m. Monoid m => Binder m -> m)
-> (forall m a. Monoid m => (a -> m) -> Binder a -> m)
-> (forall m a. Monoid m => (a -> m) -> Binder a -> m)
-> (forall a b. (a -> b -> b) -> b -> Binder a -> b)
-> (forall a b. (a -> b -> b) -> b -> Binder a -> b)
-> (forall b a. (b -> a -> b) -> b -> Binder a -> b)
-> (forall b a. (b -> a -> b) -> b -> Binder a -> b)
-> (forall a. (a -> a -> a) -> Binder a -> a)
-> (forall a. (a -> a -> a) -> Binder a -> a)
-> (forall a. Binder a -> [a])
-> (forall a. Binder a -> Bool)
-> (forall b. Binder b -> Int)
-> (forall a. Eq a => a -> Binder a -> Bool)
-> (forall a. Ord a => Binder a -> a)
-> (forall a. Ord a => Binder a -> a)
-> (forall a. Num a => Binder a -> a)
-> (forall a. Num a => Binder a -> a)
-> Foldable Binder
forall a. Eq a => a -> Binder a -> Bool
forall a. Num a => Binder a -> a
forall a. Ord a => Binder a -> a
forall m. Monoid m => Binder m -> m
forall a. Binder a -> Bool
forall b. Binder b -> Int
forall a. Binder a -> [a]
forall a. (a -> a -> a) -> Binder a -> a
forall m a. Monoid m => (a -> m) -> Binder a -> m
forall b a. (b -> a -> b) -> b -> Binder a -> b
forall a b. (a -> b -> b) -> b -> Binder a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Binder m -> m
fold :: forall m. Monoid m => Binder m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Binder a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Binder a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Binder a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Binder a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Binder a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Binder a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Binder a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Binder a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Binder a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Binder a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Binder a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Binder a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Binder a -> a
foldr1 :: forall a. (a -> a -> a) -> Binder a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Binder a -> a
foldl1 :: forall a. (a -> a -> a) -> Binder a -> a
$ctoList :: forall a. Binder a -> [a]
toList :: forall a. Binder a -> [a]
$cnull :: forall a. Binder a -> Bool
null :: forall a. Binder a -> Bool
$clength :: forall b. Binder b -> Int
length :: forall b. Binder b -> Int
$celem :: forall a. Eq a => a -> Binder a -> Bool
elem :: forall a. Eq a => a -> Binder a -> Bool
$cmaximum :: forall a. Ord a => Binder a -> a
maximum :: forall a. Ord a => Binder a -> a
$cminimum :: forall a. Ord a => Binder a -> a
minimum :: forall a. Ord a => Binder a -> a
$csum :: forall a. Num a => Binder a -> a
sum :: forall a. Num a => Binder a -> a
$cproduct :: forall a. Num a => Binder a -> a
product :: forall a. Num a => Binder a -> a
Foldable, Functor Binder
Foldable Binder
(Functor Binder, Foldable Binder) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Binder a -> f (Binder b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Binder (f a) -> f (Binder a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Binder a -> m (Binder b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Binder (m a) -> m (Binder a))
-> Traversable Binder
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Binder (m a) -> m (Binder a)
forall (f :: * -> *) a.
Applicative f =>
Binder (f a) -> f (Binder a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Binder a -> m (Binder b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Binder a -> f (Binder b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Binder a -> f (Binder b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Binder a -> f (Binder b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Binder (f a) -> f (Binder a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Binder (f a) -> f (Binder a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Binder a -> m (Binder b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Binder a -> m (Binder b)
$csequence :: forall (m :: * -> *) a. Monad m => Binder (m a) -> m (Binder a)
sequence :: forall (m :: * -> *) a. Monad m => Binder (m a) -> m (Binder a)
Traversable, Typeable (Binder b)
Typeable (Binder b) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Binder b -> c (Binder b))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Binder b))
-> (Binder b -> Constr)
-> (Binder b -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Binder b)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Binder b)))
-> ((forall b. Data b => b -> b) -> Binder b -> Binder b)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Binder b -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Binder b -> r)
-> (forall u. (forall d. Data d => d -> u) -> Binder b -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Binder b -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Binder b -> m (Binder b))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Binder b -> m (Binder b))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Binder b -> m (Binder b))
-> Data (Binder b)
Binder b -> Constr
Binder b -> DataType
(forall b. Data b => b -> b) -> Binder b -> Binder b
forall b. Data b => Typeable (Binder b)
forall b. Data b => Binder b -> Constr
forall b. Data b => Binder b -> DataType
forall b.
Data b =>
(forall b. Data b => b -> b) -> Binder b -> Binder b
forall b u.
Data b =>
Int -> (forall d. Data d => d -> u) -> Binder b -> u
forall b u.
Data b =>
(forall d. Data d => d -> u) -> Binder b -> [u]
forall b r r'.
Data b =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
forall b r r'.
Data b =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binder b)
forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binder b -> c (Binder b)
forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Binder b))
forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Binder b))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Binder b -> u
forall u. (forall d. Data d => d -> u) -> Binder b -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binder b)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binder b -> c (Binder b)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Binder b))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Binder b))
$cgfoldl :: forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binder b -> c (Binder b)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binder b -> c (Binder b)
$cgunfold :: forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binder b)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binder b)
$ctoConstr :: forall b. Data b => Binder b -> Constr
toConstr :: Binder b -> Constr
$cdataTypeOf :: forall b. Data b => Binder b -> DataType
dataTypeOf :: Binder b -> DataType
$cdataCast1 :: forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Binder b))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Binder b))
$cdataCast2 :: forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Binder b))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Binder b))
$cgmapT :: forall b.
Data b =>
(forall b. Data b => b -> b) -> Binder b -> Binder b
gmapT :: (forall b. Data b => b -> b) -> Binder b -> Binder b
$cgmapQl :: forall b r r'.
Data b =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
$cgmapQr :: forall b r r'.
Data b =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binder b -> r
$cgmapQ :: forall b u.
Data b =>
(forall d. Data d => d -> u) -> Binder b -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Binder b -> [u]
$cgmapQi :: forall b u.
Data b =>
Int -> (forall d. Data d => d -> u) -> Binder b -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Binder b -> u
$cgmapM :: forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
$cgmapMp :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
$cgmapMo :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Binder b -> m (Binder b)
Data, (forall x. Binder b -> Rep (Binder b) x)
-> (forall x. Rep (Binder b) x -> Binder b) -> Generic (Binder b)
forall x. Rep (Binder b) x -> Binder b
forall x. Binder b -> Rep (Binder b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall b x. Rep (Binder b) x -> Binder b
forall b x. Binder b -> Rep (Binder b) x
$cfrom :: forall b x. Binder b -> Rep (Binder b) x
from :: forall x. Binder b -> Rep (Binder b) x
$cto :: forall b x. Rep (Binder b) x -> Binder b
to :: forall x. Rep (Binder b) x -> Binder b
Generic, Typeable)
{-!
deriving instance Binary Binder
!-}

instance Sized a => Sized (Binder a) where
  size :: Binder a -> Int
size (Lam RigCount
_ a
ty) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty
  size (Pi RigCount
_ Maybe ImplicitInfo
_ a
ty a
_) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty
  size (Let RigCount
_ a
ty a
val) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
val
  size (NLet a
ty a
val) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
val
  size (Hole a
ty) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty
  size (GHole Int
_ [Name]
_ a
ty) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty
  size (Guess a
ty a
val) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
val
  size (PVar RigCount
_ a
ty) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty
  size (PVTy a
ty) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
ty

fmapMB :: Monad m => (a -> m b) -> Binder a -> m (Binder b)
fmapMB :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Binder a -> m (Binder b)
fmapMB a -> m b
f (Let RigCount
c a
t a
v)   = (b -> b -> Binder b) -> m b -> m b -> m (Binder b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (RigCount -> b -> b -> Binder b
forall b. RigCount -> b -> b -> Binder b
Let RigCount
c) (a -> m b
f a
t) (a -> m b
f a
v)
fmapMB a -> m b
f (NLet a
t a
v)  = (b -> b -> Binder b) -> m b -> m b -> m (Binder b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 b -> b -> Binder b
forall b. b -> b -> Binder b
NLet (a -> m b
f a
t) (a -> m b
f a
v)
fmapMB a -> m b
f (Guess a
t a
v) = (b -> b -> Binder b) -> m b -> m b -> m (Binder b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 b -> b -> Binder b
forall b. b -> b -> Binder b
Guess (a -> m b
f a
t) (a -> m b
f a
v)
fmapMB a -> m b
f (Lam RigCount
c a
t)   = (b -> Binder b) -> m b -> m (Binder b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (RigCount -> b -> Binder b
forall b. RigCount -> b -> Binder b
Lam RigCount
c) (a -> m b
f a
t)
fmapMB a -> m b
f (Pi RigCount
c Maybe ImplicitInfo
i a
t a
k) = (b -> b -> Binder b) -> m b -> m b -> m (Binder b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (RigCount -> Maybe ImplicitInfo -> b -> b -> Binder b
forall b. RigCount -> Maybe ImplicitInfo -> b -> b -> Binder b
Pi RigCount
c Maybe ImplicitInfo
i) (a -> m b
f a
t) (a -> m b
f a
k)
fmapMB a -> m b
f (Hole a
t)    = (b -> Binder b) -> m b -> m (Binder b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM b -> Binder b
forall b. b -> Binder b
Hole (a -> m b
f a
t)
fmapMB a -> m b
f (GHole Int
i [Name]
ns a
t) = (b -> Binder b) -> m b -> m (Binder b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Int -> [Name] -> b -> Binder b
forall b. Int -> [Name] -> b -> Binder b
GHole Int
i [Name]
ns) (a -> m b
f a
t)
fmapMB a -> m b
f (PVar RigCount
c a
t)    = (b -> Binder b) -> m b -> m (Binder b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (RigCount -> b -> Binder b
forall b. RigCount -> b -> Binder b
PVar RigCount
c) (a -> m b
f a
t)
fmapMB a -> m b
f (PVTy a
t)    = (b -> Binder b) -> m b -> m (Binder b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM b -> Binder b
forall b. b -> Binder b
PVTy (a -> m b
f a
t)

raw_apply :: Raw -> [Raw] -> Raw
raw_apply :: Raw -> [Raw] -> Raw
raw_apply Raw
f [] = Raw
f
raw_apply Raw
f (Raw
a : [Raw]
as) = Raw -> [Raw] -> Raw
raw_apply (Raw -> Raw -> Raw
RApp Raw
f Raw
a) [Raw]
as

raw_unapply :: Raw -> (Raw, [Raw])
raw_unapply :: Raw -> (Raw, [Raw])
raw_unapply Raw
t = [Raw] -> Raw -> (Raw, [Raw])
ua [] Raw
t where
    ua :: [Raw] -> Raw -> (Raw, [Raw])
ua [Raw]
args (RApp Raw
f Raw
a) = [Raw] -> Raw -> (Raw, [Raw])
ua (Raw
aRaw -> [Raw] -> [Raw]
forall a. a -> [a] -> [a]
:[Raw]
args) Raw
f
    ua [Raw]
args Raw
t          = (Raw
t, [Raw]
args)

-- WELL TYPED TERMS ---------------------------------------------------------

internalNS :: String
internalNS :: String
internalNS = String
"(internal)"

-- | Universe expressions for universe checking
data UExp = UVar String Int -- ^ universe variable, with source file to disambiguate
          | UVal Int -- ^ explicit universe level
  deriving (UExp -> UExp -> Bool
(UExp -> UExp -> Bool) -> (UExp -> UExp -> Bool) -> Eq UExp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UExp -> UExp -> Bool
== :: UExp -> UExp -> Bool
$c/= :: UExp -> UExp -> Bool
/= :: UExp -> UExp -> Bool
Eq, Eq UExp
Eq UExp =>
(UExp -> UExp -> Ordering)
-> (UExp -> UExp -> Bool)
-> (UExp -> UExp -> Bool)
-> (UExp -> UExp -> Bool)
-> (UExp -> UExp -> Bool)
-> (UExp -> UExp -> UExp)
-> (UExp -> UExp -> UExp)
-> Ord UExp
UExp -> UExp -> Bool
UExp -> UExp -> Ordering
UExp -> UExp -> UExp
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UExp -> UExp -> Ordering
compare :: UExp -> UExp -> Ordering
$c< :: UExp -> UExp -> Bool
< :: UExp -> UExp -> Bool
$c<= :: UExp -> UExp -> Bool
<= :: UExp -> UExp -> Bool
$c> :: UExp -> UExp -> Bool
> :: UExp -> UExp -> Bool
$c>= :: UExp -> UExp -> Bool
>= :: UExp -> UExp -> Bool
$cmax :: UExp -> UExp -> UExp
max :: UExp -> UExp -> UExp
$cmin :: UExp -> UExp -> UExp
min :: UExp -> UExp -> UExp
Ord, Typeable UExp
Typeable UExp =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> UExp -> c UExp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c UExp)
-> (UExp -> Constr)
-> (UExp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c UExp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UExp))
-> ((forall b. Data b => b -> b) -> UExp -> UExp)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r)
-> (forall u. (forall d. Data d => d -> u) -> UExp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> UExp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> UExp -> m UExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UExp -> m UExp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UExp -> m UExp)
-> Data UExp
UExp -> Constr
UExp -> DataType
(forall b. Data b => b -> b) -> UExp -> UExp
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> UExp -> u
forall u. (forall d. Data d => d -> u) -> UExp -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UExp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UExp -> c UExp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UExp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UExp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UExp -> c UExp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UExp -> c UExp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UExp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UExp
$ctoConstr :: UExp -> Constr
toConstr :: UExp -> Constr
$cdataTypeOf :: UExp -> DataType
dataTypeOf :: UExp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UExp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UExp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UExp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UExp)
$cgmapT :: (forall b. Data b => b -> b) -> UExp -> UExp
gmapT :: (forall b. Data b => b -> b) -> UExp -> UExp
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UExp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> UExp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> UExp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> UExp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> UExp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UExp -> m UExp
Data, (forall x. UExp -> Rep UExp x)
-> (forall x. Rep UExp x -> UExp) -> Generic UExp
forall x. Rep UExp x -> UExp
forall x. UExp -> Rep UExp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UExp -> Rep UExp x
from :: forall x. UExp -> Rep UExp x
$cto :: forall x. Rep UExp x -> UExp
to :: forall x. Rep UExp x -> UExp
Generic, Typeable)

instance Sized UExp where
  size :: UExp -> Int
size UExp
_ = Int
1

instance Show UExp where
    show :: UExp -> String
show (UVar String
ns Int
x)
       | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
26 = String
ns String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Int -> Char
forall a. Enum a => Int -> a
toEnum (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Char -> Int
forall a. Enum a => a -> Int
fromEnum Char
'a')]
       | Bool
otherwise = String
ns String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> Char
forall a. Enum a => Int -> a
toEnum ((Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
26) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Char -> Int
forall a. Enum a => a -> Int
fromEnum Char
'a') Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> String
forall a. Show a => a -> String
show (Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
26)
    show (UVal Int
x) = Int -> String
forall a. Show a => a -> String
show Int
x
--     show (UMax l r) = "max(" ++ show l ++ ", " ++ show r ++")"

-- | Universe constraints
data UConstraint = ULT UExp UExp -- ^ Strictly less than
                 | ULE UExp UExp -- ^ Less than or equal to
  deriving (UConstraint -> UConstraint -> Bool
(UConstraint -> UConstraint -> Bool)
-> (UConstraint -> UConstraint -> Bool) -> Eq UConstraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UConstraint -> UConstraint -> Bool
== :: UConstraint -> UConstraint -> Bool
$c/= :: UConstraint -> UConstraint -> Bool
/= :: UConstraint -> UConstraint -> Bool
Eq, Eq UConstraint
Eq UConstraint =>
(UConstraint -> UConstraint -> Ordering)
-> (UConstraint -> UConstraint -> Bool)
-> (UConstraint -> UConstraint -> Bool)
-> (UConstraint -> UConstraint -> Bool)
-> (UConstraint -> UConstraint -> Bool)
-> (UConstraint -> UConstraint -> UConstraint)
-> (UConstraint -> UConstraint -> UConstraint)
-> Ord UConstraint
UConstraint -> UConstraint -> Bool
UConstraint -> UConstraint -> Ordering
UConstraint -> UConstraint -> UConstraint
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UConstraint -> UConstraint -> Ordering
compare :: UConstraint -> UConstraint -> Ordering
$c< :: UConstraint -> UConstraint -> Bool
< :: UConstraint -> UConstraint -> Bool
$c<= :: UConstraint -> UConstraint -> Bool
<= :: UConstraint -> UConstraint -> Bool
$c> :: UConstraint -> UConstraint -> Bool
> :: UConstraint -> UConstraint -> Bool
$c>= :: UConstraint -> UConstraint -> Bool
>= :: UConstraint -> UConstraint -> Bool
$cmax :: UConstraint -> UConstraint -> UConstraint
max :: UConstraint -> UConstraint -> UConstraint
$cmin :: UConstraint -> UConstraint -> UConstraint
min :: UConstraint -> UConstraint -> UConstraint
Ord, Typeable UConstraint
Typeable UConstraint =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> UConstraint -> c UConstraint)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c UConstraint)
-> (UConstraint -> Constr)
-> (UConstraint -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c UConstraint))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c UConstraint))
-> ((forall b. Data b => b -> b) -> UConstraint -> UConstraint)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> UConstraint -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> UConstraint -> r)
-> (forall u. (forall d. Data d => d -> u) -> UConstraint -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> UConstraint -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> UConstraint -> m UConstraint)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UConstraint -> m UConstraint)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UConstraint -> m UConstraint)
-> Data UConstraint
UConstraint -> Constr
UConstraint -> DataType
(forall b. Data b => b -> b) -> UConstraint -> UConstraint
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> UConstraint -> u
forall u. (forall d. Data d => d -> u) -> UConstraint -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UConstraint -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UConstraint -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UConstraint
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UConstraint -> c UConstraint
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UConstraint)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c UConstraint)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UConstraint -> c UConstraint
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UConstraint -> c UConstraint
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UConstraint
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UConstraint
$ctoConstr :: UConstraint -> Constr
toConstr :: UConstraint -> Constr
$cdataTypeOf :: UConstraint -> DataType
dataTypeOf :: UConstraint -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UConstraint)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UConstraint)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c UConstraint)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c UConstraint)
$cgmapT :: (forall b. Data b => b -> b) -> UConstraint -> UConstraint
gmapT :: (forall b. Data b => b -> b) -> UConstraint -> UConstraint
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UConstraint -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UConstraint -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UConstraint -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UConstraint -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> UConstraint -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> UConstraint -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> UConstraint -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> UConstraint -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UConstraint -> m UConstraint
Data, (forall x. UConstraint -> Rep UConstraint x)
-> (forall x. Rep UConstraint x -> UConstraint)
-> Generic UConstraint
forall x. Rep UConstraint x -> UConstraint
forall x. UConstraint -> Rep UConstraint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UConstraint -> Rep UConstraint x
from :: forall x. UConstraint -> Rep UConstraint x
$cto :: forall x. Rep UConstraint x -> UConstraint
to :: forall x. Rep UConstraint x -> UConstraint
Generic, Typeable)

data ConstraintFC = ConstraintFC { ConstraintFC -> UConstraint
uconstraint :: UConstraint,
                                   ConstraintFC -> FC
ufc :: FC }
  deriving (Int -> ConstraintFC -> ShowS
[ConstraintFC] -> ShowS
ConstraintFC -> String
(Int -> ConstraintFC -> ShowS)
-> (ConstraintFC -> String)
-> ([ConstraintFC] -> ShowS)
-> Show ConstraintFC
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConstraintFC -> ShowS
showsPrec :: Int -> ConstraintFC -> ShowS
$cshow :: ConstraintFC -> String
show :: ConstraintFC -> String
$cshowList :: [ConstraintFC] -> ShowS
showList :: [ConstraintFC] -> ShowS
Show, Typeable ConstraintFC
Typeable ConstraintFC =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> ConstraintFC -> c ConstraintFC)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ConstraintFC)
-> (ConstraintFC -> Constr)
-> (ConstraintFC -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ConstraintFC))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ConstraintFC))
-> ((forall b. Data b => b -> b) -> ConstraintFC -> ConstraintFC)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r)
-> (forall u. (forall d. Data d => d -> u) -> ConstraintFC -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ConstraintFC -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC)
-> Data ConstraintFC
ConstraintFC -> Constr
ConstraintFC -> DataType
(forall b. Data b => b -> b) -> ConstraintFC -> ConstraintFC
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ConstraintFC -> u
forall u. (forall d. Data d => d -> u) -> ConstraintFC -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConstraintFC
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConstraintFC -> c ConstraintFC
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConstraintFC)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConstraintFC)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConstraintFC -> c ConstraintFC
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConstraintFC -> c ConstraintFC
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConstraintFC
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConstraintFC
$ctoConstr :: ConstraintFC -> Constr
toConstr :: ConstraintFC -> Constr
$cdataTypeOf :: ConstraintFC -> DataType
dataTypeOf :: ConstraintFC -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConstraintFC)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConstraintFC)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConstraintFC)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConstraintFC)
$cgmapT :: (forall b. Data b => b -> b) -> ConstraintFC -> ConstraintFC
gmapT :: (forall b. Data b => b -> b) -> ConstraintFC -> ConstraintFC
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConstraintFC -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ConstraintFC -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ConstraintFC -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConstraintFC -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConstraintFC -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstraintFC -> m ConstraintFC
Data, (forall x. ConstraintFC -> Rep ConstraintFC x)
-> (forall x. Rep ConstraintFC x -> ConstraintFC)
-> Generic ConstraintFC
forall x. Rep ConstraintFC x -> ConstraintFC
forall x. ConstraintFC -> Rep ConstraintFC x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ConstraintFC -> Rep ConstraintFC x
from :: forall x. ConstraintFC -> Rep ConstraintFC x
$cto :: forall x. Rep ConstraintFC x -> ConstraintFC
to :: forall x. Rep ConstraintFC x -> ConstraintFC
Generic, Typeable)

instance Eq ConstraintFC where
    ConstraintFC
x == :: ConstraintFC -> ConstraintFC -> Bool
== ConstraintFC
y = ConstraintFC -> UConstraint
uconstraint ConstraintFC
x UConstraint -> UConstraint -> Bool
forall a. Eq a => a -> a -> Bool
== ConstraintFC -> UConstraint
uconstraint ConstraintFC
y

instance Ord ConstraintFC where
    compare :: ConstraintFC -> ConstraintFC -> Ordering
compare ConstraintFC
x ConstraintFC
y = UConstraint -> UConstraint -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (ConstraintFC -> UConstraint
uconstraint ConstraintFC
x) (ConstraintFC -> UConstraint
uconstraint ConstraintFC
y)

instance Show UConstraint where
    show :: UConstraint -> String
show (ULT UExp
x UExp
y) = UExp -> String
forall a. Show a => a -> String
show UExp
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" < " String -> ShowS
forall a. [a] -> [a] -> [a]
++ UExp -> String
forall a. Show a => a -> String
show UExp
y
    show (ULE UExp
x UExp
y) = UExp -> String
forall a. Show a => a -> String
show UExp
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" <= " String -> ShowS
forall a. [a] -> [a] -> [a]
++ UExp -> String
forall a. Show a => a -> String
show UExp
y

type UCs = (Int, [UConstraint])

data NameType = Bound
              | Ref
              | DCon {NameType -> Int
nt_tag :: Int, NameType -> Int
nt_arity :: Int, NameType -> Bool
nt_unique :: Bool} -- ^ Data constructor
              | TCon {nt_tag :: Int, nt_arity :: Int} -- ^ Type constructor
  deriving (Int -> NameType -> ShowS
[NameType] -> ShowS
NameType -> String
(Int -> NameType -> ShowS)
-> (NameType -> String) -> ([NameType] -> ShowS) -> Show NameType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NameType -> ShowS
showsPrec :: Int -> NameType -> ShowS
$cshow :: NameType -> String
show :: NameType -> String
$cshowList :: [NameType] -> ShowS
showList :: [NameType] -> ShowS
Show, Eq NameType
Eq NameType =>
(NameType -> NameType -> Ordering)
-> (NameType -> NameType -> Bool)
-> (NameType -> NameType -> Bool)
-> (NameType -> NameType -> Bool)
-> (NameType -> NameType -> Bool)
-> (NameType -> NameType -> NameType)
-> (NameType -> NameType -> NameType)
-> Ord NameType
NameType -> NameType -> Bool
NameType -> NameType -> Ordering
NameType -> NameType -> NameType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NameType -> NameType -> Ordering
compare :: NameType -> NameType -> Ordering
$c< :: NameType -> NameType -> Bool
< :: NameType -> NameType -> Bool
$c<= :: NameType -> NameType -> Bool
<= :: NameType -> NameType -> Bool
$c> :: NameType -> NameType -> Bool
> :: NameType -> NameType -> Bool
$c>= :: NameType -> NameType -> Bool
>= :: NameType -> NameType -> Bool
$cmax :: NameType -> NameType -> NameType
max :: NameType -> NameType -> NameType
$cmin :: NameType -> NameType -> NameType
min :: NameType -> NameType -> NameType
Ord, Typeable NameType
Typeable NameType =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> NameType -> c NameType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NameType)
-> (NameType -> Constr)
-> (NameType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NameType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameType))
-> ((forall b. Data b => b -> b) -> NameType -> NameType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NameType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NameType -> r)
-> (forall u. (forall d. Data d => d -> u) -> NameType -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> NameType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NameType -> m NameType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NameType -> m NameType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NameType -> m NameType)
-> Data NameType
NameType -> Constr
NameType -> DataType
(forall b. Data b => b -> b) -> NameType -> NameType
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NameType -> u
forall u. (forall d. Data d => d -> u) -> NameType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameType -> c NameType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameType)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameType -> c NameType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NameType -> c NameType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameType
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NameType
$ctoConstr :: NameType -> Constr
toConstr :: NameType -> Constr
$cdataTypeOf :: NameType -> DataType
dataTypeOf :: NameType -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NameType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameType)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NameType)
$cgmapT :: (forall b. Data b => b -> b) -> NameType -> NameType
gmapT :: (forall b. Data b => b -> b) -> NameType -> NameType
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NameType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NameType -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NameType -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NameType -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NameType -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NameType -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NameType -> m NameType
Data, (forall x. NameType -> Rep NameType x)
-> (forall x. Rep NameType x -> NameType) -> Generic NameType
forall x. Rep NameType x -> NameType
forall x. NameType -> Rep NameType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NameType -> Rep NameType x
from :: forall x. NameType -> Rep NameType x
$cto :: forall x. Rep NameType x -> NameType
to :: forall x. Rep NameType x -> NameType
Generic, Typeable)
{-!
deriving instance Binary NameType
!-}

instance Sized NameType where
  size :: NameType -> Int
size NameType
_ = Int
1

instance Pretty NameType OutputAnnotation where
  pretty :: NameType -> Doc OutputAnnotation
pretty = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation)
-> (NameType -> String) -> NameType -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NameType -> String
forall a. Show a => a -> String
show

instance Eq NameType where
    NameType
Bound    == :: NameType -> NameType -> Bool
== NameType
Bound    = Bool
True
    NameType
Ref      == NameType
Ref      = Bool
True
    DCon Int
_ Int
a Bool
_ == DCon Int
_ Int
b Bool
_ = (Int
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
b) -- ignore tag
    TCon Int
_ Int
a == TCon Int
_ Int
b = (Int
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
b) -- ignore tag
    NameType
_        == NameType
_        = Bool
False

data AppStatus n = Complete
                 | MaybeHoles
                 | Holes [n]
    deriving (AppStatus n -> AppStatus n -> Bool
(AppStatus n -> AppStatus n -> Bool)
-> (AppStatus n -> AppStatus n -> Bool) -> Eq (AppStatus n)
forall n. Eq n => AppStatus n -> AppStatus n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall n. Eq n => AppStatus n -> AppStatus n -> Bool
== :: AppStatus n -> AppStatus n -> Bool
$c/= :: forall n. Eq n => AppStatus n -> AppStatus n -> Bool
/= :: AppStatus n -> AppStatus n -> Bool
Eq, Eq (AppStatus n)
Eq (AppStatus n) =>
(AppStatus n -> AppStatus n -> Ordering)
-> (AppStatus n -> AppStatus n -> Bool)
-> (AppStatus n -> AppStatus n -> Bool)
-> (AppStatus n -> AppStatus n -> Bool)
-> (AppStatus n -> AppStatus n -> Bool)
-> (AppStatus n -> AppStatus n -> AppStatus n)
-> (AppStatus n -> AppStatus n -> AppStatus n)
-> Ord (AppStatus n)
AppStatus n -> AppStatus n -> Bool
AppStatus n -> AppStatus n -> Ordering
AppStatus n -> AppStatus n -> AppStatus n
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall n. Ord n => Eq (AppStatus n)
forall n. Ord n => AppStatus n -> AppStatus n -> Bool
forall n. Ord n => AppStatus n -> AppStatus n -> Ordering
forall n. Ord n => AppStatus n -> AppStatus n -> AppStatus n
$ccompare :: forall n. Ord n => AppStatus n -> AppStatus n -> Ordering
compare :: AppStatus n -> AppStatus n -> Ordering
$c< :: forall n. Ord n => AppStatus n -> AppStatus n -> Bool
< :: AppStatus n -> AppStatus n -> Bool
$c<= :: forall n. Ord n => AppStatus n -> AppStatus n -> Bool
<= :: AppStatus n -> AppStatus n -> Bool
$c> :: forall n. Ord n => AppStatus n -> AppStatus n -> Bool
> :: AppStatus n -> AppStatus n -> Bool
$c>= :: forall n. Ord n => AppStatus n -> AppStatus n -> Bool
>= :: AppStatus n -> AppStatus n -> Bool
$cmax :: forall n. Ord n => AppStatus n -> AppStatus n -> AppStatus n
max :: AppStatus n -> AppStatus n -> AppStatus n
$cmin :: forall n. Ord n => AppStatus n -> AppStatus n -> AppStatus n
min :: AppStatus n -> AppStatus n -> AppStatus n
Ord, (forall a b. (a -> b) -> AppStatus a -> AppStatus b)
-> (forall a b. a -> AppStatus b -> AppStatus a)
-> Functor AppStatus
forall a b. a -> AppStatus b -> AppStatus a
forall a b. (a -> b) -> AppStatus a -> AppStatus b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> AppStatus a -> AppStatus b
fmap :: forall a b. (a -> b) -> AppStatus a -> AppStatus b
$c<$ :: forall a b. a -> AppStatus b -> AppStatus a
<$ :: forall a b. a -> AppStatus b -> AppStatus a
Functor, Typeable (AppStatus n)
Typeable (AppStatus n) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> AppStatus n -> c (AppStatus n))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (AppStatus n))
-> (AppStatus n -> Constr)
-> (AppStatus n -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (AppStatus n)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (AppStatus n)))
-> ((forall b. Data b => b -> b) -> AppStatus n -> AppStatus n)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> AppStatus n -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> AppStatus n -> r)
-> (forall u. (forall d. Data d => d -> u) -> AppStatus n -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> AppStatus n -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n))
-> Data (AppStatus n)
AppStatus n -> Constr
AppStatus n -> DataType
(forall b. Data b => b -> b) -> AppStatus n -> AppStatus n
forall n. Data n => Typeable (AppStatus n)
forall n. Data n => AppStatus n -> Constr
forall n. Data n => AppStatus n -> DataType
forall n.
Data n =>
(forall b. Data b => b -> b) -> AppStatus n -> AppStatus n
forall n u.
Data n =>
Int -> (forall d. Data d => d -> u) -> AppStatus n -> u
forall n u.
Data n =>
(forall d. Data d => d -> u) -> AppStatus n -> [u]
forall n r r'.
Data n =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
forall n r r'.
Data n =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
forall n (m :: * -> *).
(Data n, Monad m) =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
forall n (m :: * -> *).
(Data n, MonadPlus m) =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
forall n (c :: * -> *).
Data n =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AppStatus n)
forall n (c :: * -> *).
Data n =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AppStatus n -> c (AppStatus n)
forall n (t :: * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (AppStatus n))
forall n (t :: * -> * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AppStatus n))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> AppStatus n -> u
forall u. (forall d. Data d => d -> u) -> AppStatus n -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AppStatus n)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AppStatus n -> c (AppStatus n)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (AppStatus n))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AppStatus n))
$cgfoldl :: forall n (c :: * -> *).
Data n =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AppStatus n -> c (AppStatus n)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AppStatus n -> c (AppStatus n)
$cgunfold :: forall n (c :: * -> *).
Data n =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AppStatus n)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AppStatus n)
$ctoConstr :: forall n. Data n => AppStatus n -> Constr
toConstr :: AppStatus n -> Constr
$cdataTypeOf :: forall n. Data n => AppStatus n -> DataType
dataTypeOf :: AppStatus n -> DataType
$cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (AppStatus n))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (AppStatus n))
$cdataCast2 :: forall n (t :: * -> * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AppStatus n))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AppStatus n))
$cgmapT :: forall n.
Data n =>
(forall b. Data b => b -> b) -> AppStatus n -> AppStatus n
gmapT :: (forall b. Data b => b -> b) -> AppStatus n -> AppStatus n
$cgmapQl :: forall n r r'.
Data n =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
$cgmapQr :: forall n r r'.
Data n =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AppStatus n -> r
$cgmapQ :: forall n u.
Data n =>
(forall d. Data d => d -> u) -> AppStatus n -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> AppStatus n -> [u]
$cgmapQi :: forall n u.
Data n =>
Int -> (forall d. Data d => d -> u) -> AppStatus n -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> AppStatus n -> u
$cgmapM :: forall n (m :: * -> *).
(Data n, Monad m) =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
$cgmapMp :: forall n (m :: * -> *).
(Data n, MonadPlus m) =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
$cgmapMo :: forall n (m :: * -> *).
(Data n, MonadPlus m) =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AppStatus n -> m (AppStatus n)
Data, (forall x. AppStatus n -> Rep (AppStatus n) x)
-> (forall x. Rep (AppStatus n) x -> AppStatus n)
-> Generic (AppStatus n)
forall x. Rep (AppStatus n) x -> AppStatus n
forall x. AppStatus n -> Rep (AppStatus n) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (AppStatus n) x -> AppStatus n
forall n x. AppStatus n -> Rep (AppStatus n) x
$cfrom :: forall n x. AppStatus n -> Rep (AppStatus n) x
from :: forall x. AppStatus n -> Rep (AppStatus n) x
$cto :: forall n x. Rep (AppStatus n) x -> AppStatus n
to :: forall x. Rep (AppStatus n) x -> AppStatus n
Generic, Typeable, Int -> AppStatus n -> ShowS
[AppStatus n] -> ShowS
AppStatus n -> String
(Int -> AppStatus n -> ShowS)
-> (AppStatus n -> String)
-> ([AppStatus n] -> ShowS)
-> Show (AppStatus n)
forall n. Show n => Int -> AppStatus n -> ShowS
forall n. Show n => [AppStatus n] -> ShowS
forall n. Show n => AppStatus n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall n. Show n => Int -> AppStatus n -> ShowS
showsPrec :: Int -> AppStatus n -> ShowS
$cshow :: forall n. Show n => AppStatus n -> String
show :: AppStatus n -> String
$cshowList :: forall n. Show n => [AppStatus n] -> ShowS
showList :: [AppStatus n] -> ShowS
Show)

-- | Terms in the core language. The type parameter is the type of
-- identifiers used for bindings and explicit named references;
-- usually we use @TT 'Name'@.
data TT n = P NameType n (TT n) -- ^ named references with type
            -- (P for "Parameter", motivated by McKinna and Pollack's
            -- Pure Type Systems Formalized)
          | V !Int -- ^ a resolved de Bruijn-indexed variable
          | Bind n !(Binder (TT n)) (TT n) -- ^ a binding
          | App (AppStatus n) !(TT n) (TT n) -- ^ function, function type, arg
          | Constant Const -- ^ constant
          | Proj (TT n) !Int -- ^ argument projection; runtime only
                             -- (-1) is a special case for 'subtract one from BI'
          | Erased -- ^ an erased term
          | Impossible -- ^ special case for totality checking
          | Inferred (TT n) -- ^ For building case trees when coverage checkimg only.
                            -- Marks a term as being inferred by the machine, rather than
                            -- given by the programmer
          | TType UExp -- ^ the type of types at some level
          | UType Universe -- ^ Uniqueness type universe (disjoint from TType)
  deriving (Eq (TT n)
Eq (TT n) =>
(TT n -> TT n -> Ordering)
-> (TT n -> TT n -> Bool)
-> (TT n -> TT n -> Bool)
-> (TT n -> TT n -> Bool)
-> (TT n -> TT n -> Bool)
-> (TT n -> TT n -> TT n)
-> (TT n -> TT n -> TT n)
-> Ord (TT n)
TT n -> TT n -> Bool
TT n -> TT n -> Ordering
TT n -> TT n -> TT n
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall n. Ord n => Eq (TT n)
forall n. Ord n => TT n -> TT n -> Bool
forall n. Ord n => TT n -> TT n -> Ordering
forall n. Ord n => TT n -> TT n -> TT n
$ccompare :: forall n. Ord n => TT n -> TT n -> Ordering
compare :: TT n -> TT n -> Ordering
$c< :: forall n. Ord n => TT n -> TT n -> Bool
< :: TT n -> TT n -> Bool
$c<= :: forall n. Ord n => TT n -> TT n -> Bool
<= :: TT n -> TT n -> Bool
$c> :: forall n. Ord n => TT n -> TT n -> Bool
> :: TT n -> TT n -> Bool
$c>= :: forall n. Ord n => TT n -> TT n -> Bool
>= :: TT n -> TT n -> Bool
$cmax :: forall n. Ord n => TT n -> TT n -> TT n
max :: TT n -> TT n -> TT n
$cmin :: forall n. Ord n => TT n -> TT n -> TT n
min :: TT n -> TT n -> TT n
Ord, (forall a b. (a -> b) -> TT a -> TT b)
-> (forall a b. a -> TT b -> TT a) -> Functor TT
forall a b. a -> TT b -> TT a
forall a b. (a -> b) -> TT a -> TT b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> TT a -> TT b
fmap :: forall a b. (a -> b) -> TT a -> TT b
$c<$ :: forall a b. a -> TT b -> TT a
<$ :: forall a b. a -> TT b -> TT a
Functor, Typeable (TT n)
Typeable (TT n) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> TT n -> c (TT n))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (TT n))
-> (TT n -> Constr)
-> (TT n -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (TT n)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (TT n)))
-> ((forall b. Data b => b -> b) -> TT n -> TT n)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r)
-> (forall u. (forall d. Data d => d -> u) -> TT n -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> TT n -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> TT n -> m (TT n))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TT n -> m (TT n))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TT n -> m (TT n))
-> Data (TT n)
TT n -> Constr
TT n -> DataType
(forall b. Data b => b -> b) -> TT n -> TT n
forall n. Data n => Typeable (TT n)
forall n. Data n => TT n -> Constr
forall n. Data n => TT n -> DataType
forall n. Data n => (forall b. Data b => b -> b) -> TT n -> TT n
forall n u.
Data n =>
Int -> (forall d. Data d => d -> u) -> TT n -> u
forall n u. Data n => (forall d. Data d => d -> u) -> TT n -> [u]
forall n r r'.
Data n =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
forall n r r'.
Data n =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
forall n (m :: * -> *).
(Data n, Monad m) =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
forall n (m :: * -> *).
(Data n, MonadPlus m) =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
forall n (c :: * -> *).
Data n =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (TT n)
forall n (c :: * -> *).
Data n =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TT n -> c (TT n)
forall n (t :: * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (TT n))
forall n (t :: * -> * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (TT n))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TT n -> u
forall u. (forall d. Data d => d -> u) -> TT n -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (TT n)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TT n -> c (TT n)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (TT n))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (TT n))
$cgfoldl :: forall n (c :: * -> *).
Data n =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TT n -> c (TT n)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TT n -> c (TT n)
$cgunfold :: forall n (c :: * -> *).
Data n =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (TT n)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (TT n)
$ctoConstr :: forall n. Data n => TT n -> Constr
toConstr :: TT n -> Constr
$cdataTypeOf :: forall n. Data n => TT n -> DataType
dataTypeOf :: TT n -> DataType
$cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (TT n))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (TT n))
$cdataCast2 :: forall n (t :: * -> * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (TT n))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (TT n))
$cgmapT :: forall n. Data n => (forall b. Data b => b -> b) -> TT n -> TT n
gmapT :: (forall b. Data b => b -> b) -> TT n -> TT n
$cgmapQl :: forall n r r'.
Data n =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
$cgmapQr :: forall n r r'.
Data n =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TT n -> r
$cgmapQ :: forall n u. Data n => (forall d. Data d => d -> u) -> TT n -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> TT n -> [u]
$cgmapQi :: forall n u.
Data n =>
Int -> (forall d. Data d => d -> u) -> TT n -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TT n -> u
$cgmapM :: forall n (m :: * -> *).
(Data n, Monad m) =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
$cgmapMp :: forall n (m :: * -> *).
(Data n, MonadPlus m) =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
$cgmapMo :: forall n (m :: * -> *).
(Data n, MonadPlus m) =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TT n -> m (TT n)
Data, (forall x. TT n -> Rep (TT n) x)
-> (forall x. Rep (TT n) x -> TT n) -> Generic (TT n)
forall x. Rep (TT n) x -> TT n
forall x. TT n -> Rep (TT n) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (TT n) x -> TT n
forall n x. TT n -> Rep (TT n) x
$cfrom :: forall n x. TT n -> Rep (TT n) x
from :: forall x. TT n -> Rep (TT n) x
$cto :: forall n x. Rep (TT n) x -> TT n
to :: forall x. Rep (TT n) x -> TT n
Generic, Typeable)
{-!
deriving instance Binary TT
!-}

class TermSize a where
  termsize :: Name -> a -> Int

instance TermSize a => TermSize [a] where
    termsize :: Name -> [a] -> Int
termsize Name
n [] = Int
0
    termsize Name
n (a
x : [a]
xs) = Name -> a -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
n a
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> [a] -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
n [a]
xs

instance TermSize (TT Name) where
    termsize :: Name -> TT Name -> Int
termsize Name
n (P NameType
_ Name
n' TT Name
_)
       | Name
n' Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
n = Int
1000000 -- recursive => really big
       | Name -> Bool
caseName Name
n' = Int
1000000 -- case, not safe to inline for termination check
       | Bool
otherwise = Int
1
    termsize Name
n (V Int
_) = Int
1
    -- for `Bind` terms, we can erroneously declare a term
    -- "recursive => really big" if the name of the bound
    -- variable is the same as the name we're using
    -- So generate a different name in that case.
    termsize Name
n (Bind Name
n' (Let RigCount
c TT Name
t TT Name
v) TT Name
sc)
       = let rn :: Name
rn = if Name
n Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
n' then Int -> String -> Name
sMN Int
0 String
"noname" else Name
n in
             Name -> TT Name -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
rn TT Name
v Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> TT Name -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
rn TT Name
sc
    termsize Name
n (Bind Name
n' Binder (TT Name)
b TT Name
sc)
       = let rn :: Name
rn = if Name
n Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
n' then Int -> String -> Name
sMN Int
0 String
"noname" else Name
n in
             Name -> TT Name -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
rn TT Name
sc
    termsize Name
n (App AppStatus Name
_ TT Name
f TT Name
a) = Name -> TT Name -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
n TT Name
f Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> TT Name -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
n TT Name
a
    termsize Name
n (Proj TT Name
t Int
i) = Name -> TT Name -> Int
forall a. TermSize a => Name -> a -> Int
termsize Name
n TT Name
t
    termsize Name
n TT Name
_ = Int
1

instance Sized Universe where
  size :: Universe -> Int
size Universe
u = Int
1

instance Sized a => Sized (TT a) where
  size :: TT a -> Int
size (P NameType
name a
n TT a
trm) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ NameType -> Int
forall a. Sized a => a -> Int
size NameType
name Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT a -> Int
forall a. Sized a => a -> Int
size TT a
trm
  size (V Int
v) = Int
1
  size (Bind a
nm Binder (TT a)
binder TT a
bdy) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Binder (TT a) -> Int
forall a. Sized a => a -> Int
size Binder (TT a)
binder Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT a -> Int
forall a. Sized a => a -> Int
size TT a
bdy
  size (App AppStatus a
_ TT a
l TT a
r) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT a -> Int
forall a. Sized a => a -> Int
size TT a
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT a -> Int
forall a. Sized a => a -> Int
size TT a
r
  size (Constant Const
c) = Const -> Int
forall a. Sized a => a -> Int
size Const
c
  size TT a
Erased = Int
1
  size (TType UExp
u) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ UExp -> Int
forall a. Sized a => a -> Int
size UExp
u
  size (Proj TT a
a Int
_) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT a -> Int
forall a. Sized a => a -> Int
size TT a
a
  size TT a
Impossible = Int
1
  size (Inferred TT a
t) = TT a -> Int
forall a. Sized a => a -> Int
size TT a
t
  size (UType Universe
u) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Universe -> Int
forall a. Sized a => a -> Int
size Universe
u

instance Pretty a o => Pretty (TT a) o where
  pretty :: TT a -> Doc o
pretty TT a
_ = String -> Doc o
forall a. String -> Doc a
text String
"test"

data RigCount = Rig0 | Rig1 | RigW
  deriving (Int -> RigCount -> ShowS
[RigCount] -> ShowS
RigCount -> String
(Int -> RigCount -> ShowS)
-> (RigCount -> String) -> ([RigCount] -> ShowS) -> Show RigCount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RigCount -> ShowS
showsPrec :: Int -> RigCount -> ShowS
$cshow :: RigCount -> String
show :: RigCount -> String
$cshowList :: [RigCount] -> ShowS
showList :: [RigCount] -> ShowS
Show, RigCount -> RigCount -> Bool
(RigCount -> RigCount -> Bool)
-> (RigCount -> RigCount -> Bool) -> Eq RigCount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RigCount -> RigCount -> Bool
== :: RigCount -> RigCount -> Bool
$c/= :: RigCount -> RigCount -> Bool
/= :: RigCount -> RigCount -> Bool
Eq, Eq RigCount
Eq RigCount =>
(RigCount -> RigCount -> Ordering)
-> (RigCount -> RigCount -> Bool)
-> (RigCount -> RigCount -> Bool)
-> (RigCount -> RigCount -> Bool)
-> (RigCount -> RigCount -> Bool)
-> (RigCount -> RigCount -> RigCount)
-> (RigCount -> RigCount -> RigCount)
-> Ord RigCount
RigCount -> RigCount -> Bool
RigCount -> RigCount -> Ordering
RigCount -> RigCount -> RigCount
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RigCount -> RigCount -> Ordering
compare :: RigCount -> RigCount -> Ordering
$c< :: RigCount -> RigCount -> Bool
< :: RigCount -> RigCount -> Bool
$c<= :: RigCount -> RigCount -> Bool
<= :: RigCount -> RigCount -> Bool
$c> :: RigCount -> RigCount -> Bool
> :: RigCount -> RigCount -> Bool
$c>= :: RigCount -> RigCount -> Bool
>= :: RigCount -> RigCount -> Bool
$cmax :: RigCount -> RigCount -> RigCount
max :: RigCount -> RigCount -> RigCount
$cmin :: RigCount -> RigCount -> RigCount
min :: RigCount -> RigCount -> RigCount
Ord, Typeable RigCount
Typeable RigCount =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> RigCount -> c RigCount)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c RigCount)
-> (RigCount -> Constr)
-> (RigCount -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c RigCount))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RigCount))
-> ((forall b. Data b => b -> b) -> RigCount -> RigCount)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> RigCount -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> RigCount -> r)
-> (forall u. (forall d. Data d => d -> u) -> RigCount -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> RigCount -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> RigCount -> m RigCount)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> RigCount -> m RigCount)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> RigCount -> m RigCount)
-> Data RigCount
RigCount -> Constr
RigCount -> DataType
(forall b. Data b => b -> b) -> RigCount -> RigCount
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> RigCount -> u
forall u. (forall d. Data d => d -> u) -> RigCount -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RigCount -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RigCount -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RigCount
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RigCount -> c RigCount
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RigCount)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RigCount)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RigCount -> c RigCount
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RigCount -> c RigCount
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RigCount
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RigCount
$ctoConstr :: RigCount -> Constr
toConstr :: RigCount -> Constr
$cdataTypeOf :: RigCount -> DataType
dataTypeOf :: RigCount -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RigCount)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RigCount)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RigCount)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RigCount)
$cgmapT :: (forall b. Data b => b -> b) -> RigCount -> RigCount
gmapT :: (forall b. Data b => b -> b) -> RigCount -> RigCount
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RigCount -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RigCount -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RigCount -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RigCount -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> RigCount -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> RigCount -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RigCount -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RigCount -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RigCount -> m RigCount
Data, (forall x. RigCount -> Rep RigCount x)
-> (forall x. Rep RigCount x -> RigCount) -> Generic RigCount
forall x. Rep RigCount x -> RigCount
forall x. RigCount -> Rep RigCount x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RigCount -> Rep RigCount x
from :: forall x. RigCount -> Rep RigCount x
$cto :: forall x. Rep RigCount x -> RigCount
to :: forall x. Rep RigCount x -> RigCount
Generic, Typeable)

rigPlus :: RigCount -> RigCount -> RigCount
rigPlus :: RigCount -> RigCount -> RigCount
rigPlus RigCount
Rig0 RigCount
Rig0 = RigCount
Rig0
rigPlus RigCount
Rig0 RigCount
Rig1 = RigCount
Rig1
rigPlus RigCount
Rig0 RigCount
RigW = RigCount
RigW
rigPlus RigCount
Rig1 RigCount
Rig0 = RigCount
Rig1
rigPlus RigCount
Rig1 RigCount
Rig1 = RigCount
RigW
rigPlus RigCount
Rig1 RigCount
RigW = RigCount
RigW
rigPlus RigCount
RigW RigCount
Rig0 = RigCount
RigW
rigPlus RigCount
RigW RigCount
Rig1 = RigCount
RigW
rigPlus RigCount
RigW RigCount
RigW = RigCount
RigW

rigMult :: RigCount -> RigCount -> RigCount
rigMult :: RigCount -> RigCount -> RigCount
rigMult RigCount
Rig0 RigCount
Rig0 = RigCount
Rig0
rigMult RigCount
Rig0 RigCount
Rig1 = RigCount
Rig0
rigMult RigCount
Rig0 RigCount
RigW = RigCount
Rig0
rigMult RigCount
Rig1 RigCount
Rig0 = RigCount
Rig0
rigMult RigCount
Rig1 RigCount
Rig1 = RigCount
Rig1
rigMult RigCount
Rig1 RigCount
RigW = RigCount
RigW
rigMult RigCount
RigW RigCount
Rig0 = RigCount
Rig0
rigMult RigCount
RigW RigCount
Rig1 = RigCount
RigW
rigMult RigCount
RigW RigCount
RigW = RigCount
RigW

type EnvTT n = [(n, RigCount, Binder (TT n))]

fstEnv :: (a, b, c) -> a
fstEnv (a
n, b
c, c
b) = a
n
rigEnv :: (a, b, c) -> b
rigEnv (a
n, b
c, c
b) = b
c
sndEnv :: (a, b, c) -> c
sndEnv (a
n, b
c, c
b) = c
b

envBinders :: [(a, b, b)] -> [(a, b)]
envBinders = ((a, b, b) -> (a, b)) -> [(a, b, b)] -> [(a, b)]
forall a b. (a -> b) -> [a] -> [b]
map (\(a
n, b
_, b
b) -> (a
n, b
b))
envZero :: [(a, b, c)] -> [(a, RigCount, c)]
envZero = ((a, b, c) -> (a, RigCount, c))
-> [(a, b, c)] -> [(a, RigCount, c)]
forall a b. (a -> b) -> [a] -> [b]
map (\(a
n, b
_, c
b) -> (a
n, RigCount
Rig0, c
b))

lookupBinder :: Eq n => n -> EnvTT n -> Maybe (Binder (TT n))
lookupBinder :: forall n. Eq n => n -> EnvTT n -> Maybe (Binder (TT n))
lookupBinder n
n = n -> [(n, Binder (TT n))] -> Maybe (Binder (TT n))
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup n
n ([(n, Binder (TT n))] -> Maybe (Binder (TT n)))
-> (EnvTT n -> [(n, Binder (TT n))])
-> EnvTT n
-> Maybe (Binder (TT n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EnvTT n -> [(n, Binder (TT n))]
forall {a} {b} {b}. [(a, b, b)] -> [(a, b)]
envBinders

data Datatype n = Data { forall n. Datatype n -> n
d_typename :: n,
                         forall n. Datatype n -> Int
d_typetag  :: Int,
                         forall n. Datatype n -> TT n
d_type     :: (TT n),
                         forall n. Datatype n -> Bool
d_unique   :: Bool,
                         forall n. Datatype n -> [(n, TT n)]
d_cons     :: [(n, TT n)] }
  deriving (Int -> Datatype n -> ShowS
[Datatype n] -> ShowS
Datatype n -> String
(Int -> Datatype n -> ShowS)
-> (Datatype n -> String)
-> ([Datatype n] -> ShowS)
-> Show (Datatype n)
forall n. (Show n, Eq n) => Int -> Datatype n -> ShowS
forall n. (Show n, Eq n) => [Datatype n] -> ShowS
forall n. (Show n, Eq n) => Datatype n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall n. (Show n, Eq n) => Int -> Datatype n -> ShowS
showsPrec :: Int -> Datatype n -> ShowS
$cshow :: forall n. (Show n, Eq n) => Datatype n -> String
show :: Datatype n -> String
$cshowList :: forall n. (Show n, Eq n) => [Datatype n] -> ShowS
showList :: [Datatype n] -> ShowS
Show, (forall a b. (a -> b) -> Datatype a -> Datatype b)
-> (forall a b. a -> Datatype b -> Datatype a) -> Functor Datatype
forall a b. a -> Datatype b -> Datatype a
forall a b. (a -> b) -> Datatype a -> Datatype b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Datatype a -> Datatype b
fmap :: forall a b. (a -> b) -> Datatype a -> Datatype b
$c<$ :: forall a b. a -> Datatype b -> Datatype a
<$ :: forall a b. a -> Datatype b -> Datatype a
Functor, Datatype n -> Datatype n -> Bool
(Datatype n -> Datatype n -> Bool)
-> (Datatype n -> Datatype n -> Bool) -> Eq (Datatype n)
forall n. Eq n => Datatype n -> Datatype n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall n. Eq n => Datatype n -> Datatype n -> Bool
== :: Datatype n -> Datatype n -> Bool
$c/= :: forall n. Eq n => Datatype n -> Datatype n -> Bool
/= :: Datatype n -> Datatype n -> Bool
Eq)

-- | Data declaration options
data DataOpt = Codata -- ^ Set if the the data-type is coinductive
             | DataErrRev
    deriving (Int -> DataOpt -> ShowS
[DataOpt] -> ShowS
DataOpt -> String
(Int -> DataOpt -> ShowS)
-> (DataOpt -> String) -> ([DataOpt] -> ShowS) -> Show DataOpt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DataOpt -> ShowS
showsPrec :: Int -> DataOpt -> ShowS
$cshow :: DataOpt -> String
show :: DataOpt -> String
$cshowList :: [DataOpt] -> ShowS
showList :: [DataOpt] -> ShowS
Show, DataOpt -> DataOpt -> Bool
(DataOpt -> DataOpt -> Bool)
-> (DataOpt -> DataOpt -> Bool) -> Eq DataOpt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DataOpt -> DataOpt -> Bool
== :: DataOpt -> DataOpt -> Bool
$c/= :: DataOpt -> DataOpt -> Bool
/= :: DataOpt -> DataOpt -> Bool
Eq, (forall x. DataOpt -> Rep DataOpt x)
-> (forall x. Rep DataOpt x -> DataOpt) -> Generic DataOpt
forall x. Rep DataOpt x -> DataOpt
forall x. DataOpt -> Rep DataOpt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DataOpt -> Rep DataOpt x
from :: forall x. DataOpt -> Rep DataOpt x
$cto :: forall x. Rep DataOpt x -> DataOpt
to :: forall x. Rep DataOpt x -> DataOpt
Generic)

type DataOpts = [DataOpt]

data TypeInfo = TI { TypeInfo -> [Name]
con_names :: [Name],
                     TypeInfo -> Bool
codata :: Bool,
                     TypeInfo -> [DataOpt]
data_opts :: DataOpts,
                     TypeInfo -> [Int]
param_pos :: [Int],
                     TypeInfo -> [Name]
mutual_types :: [Name],
                     TypeInfo -> Bool
linear_con :: Bool -- is there a linear argument?
                   }
    deriving (Int -> TypeInfo -> ShowS
[TypeInfo] -> ShowS
TypeInfo -> String
(Int -> TypeInfo -> ShowS)
-> (TypeInfo -> String) -> ([TypeInfo] -> ShowS) -> Show TypeInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TypeInfo -> ShowS
showsPrec :: Int -> TypeInfo -> ShowS
$cshow :: TypeInfo -> String
show :: TypeInfo -> String
$cshowList :: [TypeInfo] -> ShowS
showList :: [TypeInfo] -> ShowS
Show, (forall x. TypeInfo -> Rep TypeInfo x)
-> (forall x. Rep TypeInfo x -> TypeInfo) -> Generic TypeInfo
forall x. Rep TypeInfo x -> TypeInfo
forall x. TypeInfo -> Rep TypeInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TypeInfo -> Rep TypeInfo x
from :: forall x. TypeInfo -> Rep TypeInfo x
$cto :: forall x. Rep TypeInfo x -> TypeInfo
to :: forall x. Rep TypeInfo x -> TypeInfo
Generic)
{-!
deriving instance Binary TypeInfo
!-}

instance Eq n => Eq (TT n) where
    == :: TT n -> TT n -> Bool
(==) (P NameType
xt n
x TT n
_)     (P NameType
yt n
y TT n
_)     = n
x n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
y
    (==) (V Int
x)          (V Int
y)          = Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
y
    (==) (Bind n
_ Binder (TT n)
xb TT n
xs) (Bind n
_ Binder (TT n)
yb TT n
ys) = TT n
xs TT n -> TT n -> Bool
forall a. Eq a => a -> a -> Bool
== TT n
ys Bool -> Bool -> Bool
&& Binder (TT n)
xb Binder (TT n) -> Binder (TT n) -> Bool
forall a. Eq a => a -> a -> Bool
== Binder (TT n)
yb
    (==) (App AppStatus n
_ TT n
fx TT n
ax)  (App AppStatus n
_ TT n
fy TT n
ay)  = TT n
ax TT n -> TT n -> Bool
forall a. Eq a => a -> a -> Bool
== TT n
ay Bool -> Bool -> Bool
&& TT n
fx TT n -> TT n -> Bool
forall a. Eq a => a -> a -> Bool
== TT n
fy
    (==) (TType UExp
_)      (TType UExp
_)      = Bool
True -- deal with constraints later
    (==) (Constant Const
x)   (Constant Const
y)   = Const
x Const -> Const -> Bool
forall a. Eq a => a -> a -> Bool
== Const
y
    (==) (Proj TT n
x Int
i)     (Proj TT n
y Int
j)     = TT n
x TT n -> TT n -> Bool
forall a. Eq a => a -> a -> Bool
== TT n
y Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
j
    (==) TT n
Erased         TT n
_              = Bool
True
    (==) TT n
_              TT n
Erased         = Bool
True
    (==) TT n
_              TT n
_              = Bool
False

-- * A few handy operations on well typed terms:

-- | A term is injective iff it is a data constructor, type constructor,
-- constant, the type Type, pi-binding, or an application of an injective
-- term.
isInjective :: TT n -> Bool
isInjective :: forall n. TT n -> Bool
isInjective (P (DCon Int
_ Int
_ Bool
_) n
_ TT n
_) = Bool
True
isInjective (P (TCon Int
_ Int
_) n
_ TT n
_) = Bool
True
isInjective (Constant Const
_)       = Bool
True
isInjective (TType UExp
x)          = Bool
True
isInjective (Bind n
_ (Pi RigCount
_ Maybe ImplicitInfo
_ TT n
_ TT n
_) TT n
sc) = Bool
True
isInjective (App AppStatus n
_ TT n
f TT n
a)        = TT n -> Bool
forall n. TT n -> Bool
isInjective TT n
f
isInjective TT n
_                  = Bool
False

-- | Replace the outermost (index 0) de Bruijn variable with the given term
instantiate :: TT n -> TT n -> TT n
instantiate :: forall n. TT n -> TT n -> TT n
instantiate TT n
e = Int -> TT n -> TT n
subst Int
0 where
    subst :: Int -> TT n -> TT n
subst Int
i (P NameType
nt n
x TT n
ty) = NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
nt n
x (Int -> TT n -> TT n
subst Int
i TT n
ty)
    subst Int
i (V Int
x) | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
x = TT n
e
    subst Int
i (Bind n
x Binder (TT n)
b TT n
sc) = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> TT n -> TT n
subst Int
i) Binder (TT n)
b) (Int -> TT n -> TT n
subst (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) TT n
sc)
    subst Int
i (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (Int -> TT n -> TT n
subst Int
i TT n
f) (Int -> TT n -> TT n
subst Int
i TT n
a)
    subst Int
i (Proj TT n
x Int
idx) = TT n -> Int -> TT n
forall n. TT n -> Int -> TT n
Proj (Int -> TT n -> TT n
subst Int
i TT n
x) Int
idx
    subst Int
i TT n
t = TT n
t

-- | As 'instantiate', but also decrement the indices of all de Bruijn variables
-- remaining in the term, so that there are no more references to the variable
-- that has been substituted.
substV :: TT n -> TT n -> TT n
substV :: forall n. TT n -> TT n -> TT n
substV TT n
x TT n
tm = Int -> TT n -> TT n
forall {n}. Int -> TT n -> TT n
dropV Int
0 (TT n -> TT n -> TT n
forall n. TT n -> TT n -> TT n
instantiate TT n
x TT n
tm) where
    dropV :: Int -> TT n -> TT n
dropV Int
i (P NameType
nt n
x TT n
ty) = NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
nt n
x (Int -> TT n -> TT n
dropV Int
i TT n
ty)
    dropV Int
i (V Int
x) | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
i = Int -> TT n
forall n. Int -> TT n
V (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
                  | Bool
otherwise = Int -> TT n
forall n. Int -> TT n
V Int
x
    dropV Int
i (Bind n
x Binder (TT n)
b TT n
sc) = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> TT n -> TT n
dropV Int
i) Binder (TT n)
b) (Int -> TT n -> TT n
dropV (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) TT n
sc)
    dropV Int
i (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (Int -> TT n -> TT n
dropV Int
i TT n
f) (Int -> TT n -> TT n
dropV Int
i TT n
a)
    dropV Int
i (Proj TT n
x Int
idx) = TT n -> Int -> TT n
forall n. TT n -> Int -> TT n
Proj (Int -> TT n -> TT n
dropV Int
i TT n
x) Int
idx
    dropV Int
i TT n
t = TT n
t

-- | Replace all non-free de Bruijn references in the given term with references
-- to the name of their binding.
explicitNames :: TT n -> TT n
explicitNames :: forall n. TT n -> TT n
explicitNames (Bind n
x Binder (TT n)
b TT n
sc) = let b' :: Binder (TT n)
b' = (TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TT n -> TT n
forall n. TT n -> TT n
explicitNames Binder (TT n)
b in
                                  n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x Binder (TT n)
b'
                                     (TT n -> TT n
forall n. TT n -> TT n
explicitNames (TT n -> TT n -> TT n
forall n. TT n -> TT n -> TT n
instantiate
                                        (NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
Bound n
x (Binder (TT n) -> TT n
forall b. Binder b -> b
binderTy Binder (TT n)
b')) TT n
sc))
explicitNames (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (TT n -> TT n
forall n. TT n -> TT n
explicitNames TT n
f) (TT n -> TT n
forall n. TT n -> TT n
explicitNames TT n
a)
explicitNames (Proj TT n
x Int
idx) = TT n -> Int -> TT n
forall n. TT n -> Int -> TT n
Proj (TT n -> TT n
forall n. TT n -> TT n
explicitNames TT n
x) Int
idx
explicitNames TT n
t = TT n
t

-- | Replace references to the given 'Name'-like id with references to
-- de Bruijn index 0.
pToV :: Eq n => n -> TT n -> TT n
pToV :: forall n. Eq n => n -> TT n -> TT n
pToV n
n = n -> Int -> TT n -> TT n
forall {t}. Eq t => t -> Int -> TT t -> TT t
pToV' n
n Int
0
pToV' :: t -> Int -> TT t -> TT t
pToV' t
n Int
i (P NameType
_ t
x TT t
_) | t
n t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== t
x = Int -> TT t
forall n. Int -> TT n
V Int
i
pToV' t
n Int
i (Bind t
x Binder (TT t)
b TT t
sc)
-- We can assume the inner scope has been pToVed already, so continue to
-- resolve names from the *outer* scope which may happen to have the same id.
     | t
n t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== t
x    = t -> Binder (TT t) -> TT t -> TT t
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind t
x ((TT t -> TT t) -> Binder (TT t) -> Binder (TT t)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (t -> Int -> TT t -> TT t
pToV' t
n Int
i) Binder (TT t)
b) TT t
sc
     | Bool
otherwise = t -> Binder (TT t) -> TT t -> TT t
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind t
x ((TT t -> TT t) -> Binder (TT t) -> Binder (TT t)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (t -> Int -> TT t -> TT t
pToV' t
n Int
i) Binder (TT t)
b) (t -> Int -> TT t -> TT t
pToV' t
n (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) TT t
sc)
pToV' t
n Int
i (App AppStatus t
s TT t
f TT t
a) = AppStatus t -> TT t -> TT t -> TT t
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus t
s (t -> Int -> TT t -> TT t
pToV' t
n Int
i TT t
f) (t -> Int -> TT t -> TT t
pToV' t
n Int
i TT t
a)
pToV' t
n Int
i (Proj TT t
t Int
idx) = TT t -> Int -> TT t
forall n. TT n -> Int -> TT n
Proj (t -> Int -> TT t -> TT t
pToV' t
n Int
i TT t
t) Int
idx
pToV' t
n Int
i TT t
t = TT t
t

-- increase de Bruijn indices, as if a binder has been added
addBinder :: TT n -> TT n
addBinder :: forall n. TT n -> TT n
addBinder TT n
t = Int -> TT n -> TT n
forall {n}. Int -> TT n -> TT n
ab Int
0 TT n
t
  where
     ab :: Int -> TT n -> TT n
ab Int
top (V Int
i) | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
top = Int -> TT n
forall n. Int -> TT n
V (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
                  | Bool
otherwise = Int -> TT n
forall n. Int -> TT n
V Int
i
     ab Int
top (Bind n
x Binder (TT n)
b TT n
sc) = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> TT n -> TT n
ab Int
top) Binder (TT n)
b) (Int -> TT n -> TT n
ab (Int
top Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) TT n
sc)
     ab Int
top (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (Int -> TT n -> TT n
ab Int
top TT n
f) (Int -> TT n -> TT n
ab Int
top TT n
a)
     ab Int
top (Proj TT n
t Int
idx) = TT n -> Int -> TT n
forall n. TT n -> Int -> TT n
Proj (Int -> TT n -> TT n
ab Int
top TT n
t) Int
idx
     ab Int
top TT n
t = TT n
t

-- | Convert several names. First in the list comes out as V 0
pToVs :: Eq n => [n] -> TT n -> TT n
pToVs :: forall n. Eq n => [n] -> TT n -> TT n
pToVs [n]
ns TT n
tm = [n] -> TT n -> Int -> TT n
forall {t}. Eq t => [t] -> TT t -> Int -> TT t
pToVs' [n]
ns TT n
tm Int
0 where
    pToVs' :: [t] -> TT t -> Int -> TT t
pToVs' []     TT t
tm Int
i = TT t
tm
    pToVs' (t
n:[t]
ns) TT t
tm Int
i = t -> Int -> TT t -> TT t
forall {t}. Eq t => t -> Int -> TT t -> TT t
pToV' t
n Int
i ([t] -> TT t -> Int -> TT t
pToVs' [t]
ns TT t
tm (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1))

-- | Replace de Bruijn indices in the given term with explicit references to
-- the names of the bindings they refer to. It is an error if the given term
-- contains free de Bruijn indices.
vToP :: TT n -> TT n
vToP :: forall n. TT n -> TT n
vToP = [(n, Binder (TT n))] -> TT n -> TT n
forall {n}. [(n, Binder (TT n))] -> TT n -> TT n
vToP' [] where
    vToP' :: [(n, Binder (TT n))] -> TT n -> TT n
vToP' [(n, Binder (TT n))]
env (V Int
i) = let (n
n, Binder (TT n)
b) = ([(n, Binder (TT n))]
env [(n, Binder (TT n))] -> Int -> (n, Binder (TT n))
forall a. HasCallStack => [a] -> Int -> a
!! Int
i) in
                          NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
Bound n
n (Binder (TT n) -> TT n
forall b. Binder b -> b
binderTy Binder (TT n)
b)
    vToP' [(n, Binder (TT n))]
env (Bind n
n Binder (TT n)
b TT n
sc) = let b' :: Binder (TT n)
b' = (TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([(n, Binder (TT n))] -> TT n -> TT n
vToP' [(n, Binder (TT n))]
env) Binder (TT n)
b in
                                  n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
n Binder (TT n)
b' ([(n, Binder (TT n))] -> TT n -> TT n
vToP' ((n
n, Binder (TT n)
b')(n, Binder (TT n)) -> [(n, Binder (TT n))] -> [(n, Binder (TT n))]
forall a. a -> [a] -> [a]
:[(n, Binder (TT n))]
env) TT n
sc)
    vToP' [(n, Binder (TT n))]
env (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s ([(n, Binder (TT n))] -> TT n -> TT n
vToP' [(n, Binder (TT n))]
env TT n
f) ([(n, Binder (TT n))] -> TT n -> TT n
vToP' [(n, Binder (TT n))]
env TT n
a)
    vToP' [(n, Binder (TT n))]
env TT n
t = TT n
t

-- | Replace every non-free reference to the name of a binding in
-- the given term with a de Bruijn index.
finalise :: Eq n => TT n -> TT n
finalise :: forall n. Eq n => TT n -> TT n
finalise (Bind n
x Binder (TT n)
b TT n
sc) = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TT n -> TT n
forall n. Eq n => TT n -> TT n
finalise Binder (TT n)
b) (n -> TT n -> TT n
forall n. Eq n => n -> TT n -> TT n
pToV n
x (TT n -> TT n
forall n. Eq n => TT n -> TT n
finalise TT n
sc))
finalise (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (TT n -> TT n
forall n. Eq n => TT n -> TT n
finalise TT n
f) (TT n -> TT n
forall n. Eq n => TT n -> TT n
finalise TT n
a)
finalise TT n
t = TT n
t

-- Once we've finished checking everything about a term we no longer need
-- the type on the 'P' so erase it so save memory

pEraseType :: TT n -> TT n
pEraseType :: forall n. TT n -> TT n
pEraseType (P NameType
nt n
t TT n
_) = NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
nt n
t TT n
forall n. TT n
Erased
pEraseType (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (TT n -> TT n
forall n. TT n -> TT n
pEraseType TT n
f) (TT n -> TT n
forall n. TT n -> TT n
pEraseType TT n
a)
pEraseType (Bind n
n Binder (TT n)
b TT n
sc) = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
n ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TT n -> TT n
forall n. TT n -> TT n
pEraseType Binder (TT n)
b) (TT n -> TT n
forall n. TT n -> TT n
pEraseType TT n
sc)
pEraseType TT n
t = TT n
t

-- | As 'instantiate', but in addition to replacing @'V' 0@,
-- replace references to the given 'Name'-like id.
subst :: Eq n => n {-^ The id to replace -} ->
         TT n {-^ The replacement term -} ->
         TT n {-^ The term to replace in -} ->
         TT n
-- subst n v tm = instantiate v (pToV n tm)
subst :: forall n. Eq n => n -> TT n -> TT n -> TT n
subst n
n TT n
v TT n
tm = (TT n, Bool) -> TT n
forall a b. (a, b) -> a
fst ((TT n, Bool) -> TT n) -> (TT n, Bool) -> TT n
forall a b. (a -> b) -> a -> b
$ Int -> TT n -> (TT n, Bool)
subst' Int
0 TT n
tm
  where
    -- keep track of updates to save allocations - this is a big win on
    -- large terms in particular
    -- ('Maybe' would be neater here, but >>= is not the right combinator.
    -- Feel free to tidy up, as long as it still saves allocating when no
    -- substitution happens...)
    subst' :: Int -> TT n -> (TT n, Bool)
subst' Int
i (V Int
x) | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
x = (TT n
v, Bool
True)
    subst' Int
i (P NameType
_ n
x TT n
_) | n
n n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
x = (TT n
v, Bool
True)
    subst' Int
i t :: TT n
t@(P NameType
nt n
x TT n
ty)
         = let (TT n
ty', Bool
ut) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
ty in
               if Bool
ut then (NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
nt n
x TT n
ty', Bool
True) else (TT n
t, Bool
False)
    subst' Int
i t :: TT n
t@(Bind n
x Binder (TT n)
b TT n
sc) | n
x n -> n -> Bool
forall a. Eq a => a -> a -> Bool
/= n
n
         = let (Binder (TT n)
b', Bool
ub) = Int -> Binder (TT n) -> (Binder (TT n), Bool)
substB' Int
i Binder (TT n)
b
               (TT n
sc', Bool
usc) = Int -> TT n -> (TT n, Bool)
subst' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) TT n
sc in
               if Bool
ub Bool -> Bool -> Bool
|| Bool
usc then (n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x Binder (TT n)
b' TT n
sc', Bool
True) else (TT n
t, Bool
False)
    subst' Int
i t :: TT n
t@(App AppStatus n
s TT n
f TT n
a) = let (TT n
f', Bool
uf) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
f
                                 (TT n
a', Bool
ua) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
a in
                                 if Bool
uf Bool -> Bool -> Bool
|| Bool
ua then (AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s TT n
f' TT n
a', Bool
True) else (TT n
t, Bool
False)
    subst' Int
i t :: TT n
t@(Proj TT n
x Int
idx) = let (TT n
x', Bool
u) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
x in
                                  if Bool
u then (TT n -> Int -> TT n
forall n. TT n -> Int -> TT n
Proj TT n
x' Int
idx, Bool
u) else (TT n
t, Bool
False)
    subst' Int
i TT n
t = (TT n
t, Bool
False)

    substB' :: Int -> Binder (TT n) -> (Binder (TT n), Bool)
substB' Int
i b :: Binder (TT n)
b@(Let RigCount
c TT n
t TT n
v) = let (TT n
t', Bool
ut) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
t
                                  (TT n
v', Bool
uv) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
v in
                                  if Bool
ut Bool -> Bool -> Bool
|| Bool
uv then (RigCount -> TT n -> TT n -> Binder (TT n)
forall b. RigCount -> b -> b -> Binder b
Let RigCount
c TT n
t' TT n
v', Bool
True)
                                              else (Binder (TT n)
b, Bool
False)
    substB' Int
i b :: Binder (TT n)
b@(Guess TT n
t TT n
v) = let (TT n
t', Bool
ut) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
t
                                  (TT n
v', Bool
uv) = Int -> TT n -> (TT n, Bool)
subst' Int
i TT n
v in
                                  if Bool
ut Bool -> Bool -> Bool
|| Bool
uv then (TT n -> TT n -> Binder (TT n)
forall b. b -> b -> Binder b
Guess TT n
t' TT n
v', Bool
True)
                                              else (Binder (TT n)
b, Bool
False)
    substB' Int
i Binder (TT n)
b = let (TT n
ty', Bool
u) = Int -> TT n -> (TT n, Bool)
subst' Int
i (Binder (TT n) -> TT n
forall b. Binder b -> b
binderTy Binder (TT n)
b) in
                      if Bool
u then (Binder (TT n)
b { binderTy = ty' }, Bool
u) else (Binder (TT n)
b, Bool
False)

-- If there are no Vs in the term (i.e. in proof state)
psubst :: Eq n => n -> TT n -> TT n -> TT n
psubst :: forall n. Eq n => n -> TT n -> TT n -> TT n
psubst n
n TT n
v TT n
tm = Int -> TT n -> TT n
s' Int
0 TT n
tm where
   s' :: Int -> TT n -> TT n
s' Int
i (V Int
x) | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
i = Int -> TT n
forall n. Int -> TT n
V (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
              | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i = TT n
v
              | Bool
otherwise = Int -> TT n
forall n. Int -> TT n
V Int
x
   s' Int
i (P NameType
_ n
x TT n
_) | n
n n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
x = TT n
v
   s' Int
i (Bind n
x Binder (TT n)
b TT n
sc) | n
n n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
x = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> TT n -> TT n
s' Int
i) Binder (TT n)
b) TT n
sc
                      | Bool
otherwise = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> TT n -> TT n
s' Int
i) Binder (TT n)
b) (Int -> TT n -> TT n
s' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) TT n
sc)
   s' Int
i (App AppStatus n
st TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
st (Int -> TT n -> TT n
s' Int
i TT n
f) (Int -> TT n -> TT n
s' Int
i TT n
a)
   s' Int
i (Proj TT n
t Int
idx) = TT n -> Int -> TT n
forall n. TT n -> Int -> TT n
Proj (Int -> TT n -> TT n
s' Int
i TT n
t) Int
idx
   s' Int
i TT n
t = TT n
t

-- | As 'subst', but takes a list of (name, substitution) pairs instead
-- of a single name and substitution
substNames :: Eq n => [(n, TT n)] -> TT n -> TT n
substNames :: forall n. Eq n => [(n, TT n)] -> TT n -> TT n
substNames []             TT n
t = TT n
t
substNames ((n
n, TT n
tm) : [(n, TT n)]
xs) TT n
t = n -> TT n -> TT n -> TT n
forall n. Eq n => n -> TT n -> TT n -> TT n
subst n
n TT n
tm ([(n, TT n)] -> TT n -> TT n
forall n. Eq n => [(n, TT n)] -> TT n -> TT n
substNames [(n, TT n)]
xs TT n
t)

-- | Replaces all terms equal (in the sense of @(==)@) to
-- the old term with the new term.
substTerm :: Eq n => TT n {-^ Old term -} ->
             TT n {-^ New term -} ->
             TT n {-^ template term -}
             -> TT n
substTerm :: forall n. Eq n => TT n -> TT n -> TT n -> TT n
substTerm TT n
old TT n
new = TT n -> TT n
st where
  st :: TT n -> TT n
st TT n
t | [(n, n)] -> TT n -> TT n -> Bool
forall {b}. Eq b => [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [] TT n
t TT n
old = TT n
new
  st (App AppStatus n
s TT n
f TT n
a) = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (TT n -> TT n
st TT n
f) (TT n -> TT n
st TT n
a)
  st (Bind n
x Binder (TT n)
b TT n
sc) = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x ((TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TT n -> TT n
st Binder (TT n)
b) (TT n -> TT n
st TT n
sc)
  st TT n
t = TT n
t

  eqAlpha :: [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as (P NameType
_ b
x TT b
_) (P NameType
_ b
y TT b
_)
       = b
x b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
y Bool -> Bool -> Bool
|| (b
x, b
y) (b, b) -> [(b, b)] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [(b, b)]
as Bool -> Bool -> Bool
|| (b
y, b
x) (b, b) -> [(b, b)] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [(b, b)]
as
  eqAlpha [(b, b)]
as (V Int
x) (V Int
y) = Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
y
  eqAlpha [(b, b)]
as (Bind b
x Binder (TT b)
xb TT b
xs) (Bind b
y Binder (TT b)
yb TT b
ys)
       = [(b, b)] -> Binder (TT b) -> Binder (TT b) -> Bool
eqAlphaB [(b, b)]
as Binder (TT b)
xb Binder (TT b)
yb Bool -> Bool -> Bool
&& [(b, b)] -> TT b -> TT b -> Bool
eqAlpha ((b
x, b
y) (b, b) -> [(b, b)] -> [(b, b)]
forall a. a -> [a] -> [a]
: [(b, b)]
as) TT b
xs TT b
ys
  eqAlpha [(b, b)]
as (App AppStatus b
_ TT b
fx TT b
ax) (App AppStatus b
_ TT b
fy TT b
ay) = [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as TT b
fx TT b
fy Bool -> Bool -> Bool
&& [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as TT b
ax TT b
ay
  eqAlpha [(b, b)]
as TT b
x TT b
y = TT b
x TT b -> TT b -> Bool
forall a. Eq a => a -> a -> Bool
== TT b
y

  eqAlphaB :: [(b, b)] -> Binder (TT b) -> Binder (TT b) -> Bool
eqAlphaB [(b, b)]
as (Let RigCount
xc TT b
xt TT b
xv) (Let RigCount
yc TT b
yt TT b
yv)
       = [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as TT b
xt TT b
yt Bool -> Bool -> Bool
&& [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as TT b
xv TT b
yv
  eqAlphaB [(b, b)]
as (Guess TT b
xt TT b
xv) (Guess TT b
yt TT b
yv)
       = [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as TT b
xt TT b
yt Bool -> Bool -> Bool
&& [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as TT b
xv TT b
yv
  eqAlphaB [(b, b)]
as Binder (TT b)
bx Binder (TT b)
by = [(b, b)] -> TT b -> TT b -> Bool
eqAlpha [(b, b)]
as (Binder (TT b) -> TT b
forall b. Binder b -> b
binderTy Binder (TT b)
bx) (Binder (TT b) -> TT b
forall b. Binder b -> b
binderTy Binder (TT b)
by)

-- | Return number of occurrences of V 0 or bound name i the term
occurrences :: Eq n => n -> TT n -> Int
occurrences :: forall n. Eq n => n -> TT n -> Int
occurrences n
n TT n
t = State Int () -> Int -> Int
forall s a. State s a -> s -> s
execState (Int -> TT n -> State Int ()
forall {s} {m :: * -> *}.
(Num s, MonadState s m) =>
Int -> TT n -> m ()
no' Int
0 TT n
t) Int
0
  where
    no' :: Int -> TT n -> m ()
no' Int
i (V Int
x) | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
x = do s
num <- m s
forall s (m :: * -> *). MonadState s m => m s
get; s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (s
num s -> s -> s
forall a. Num a => a -> a -> a
+ s
1)
    no' Int
i (P NameType
Bound n
x TT n
_) | n
n n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
x = do s
num <- m s
forall s (m :: * -> *). MonadState s m => m s
get; s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (s
num s -> s -> s
forall a. Num a => a -> a -> a
+ s
1)
    no' Int
i (Bind n
n Binder (TT n)
b TT n
sc) = do Int -> Binder (TT n) -> m ()
noB' Int
i Binder (TT n)
b; Int -> TT n -> m ()
no' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) TT n
sc
       where noB' :: Int -> Binder (TT n) -> m ()
noB' Int
i (Let RigCount
c TT n
t TT n
v) = do Int -> TT n -> m ()
no' Int
i TT n
t; Int -> TT n -> m ()
no' Int
i TT n
v
             noB' Int
i (Guess TT n
t TT n
v) = do Int -> TT n -> m ()
no' Int
i TT n
t; Int -> TT n -> m ()
no' Int
i TT n
v
             noB' Int
i Binder (TT n)
b = Int -> TT n -> m ()
no' Int
i (Binder (TT n) -> TT n
forall b. Binder b -> b
binderTy Binder (TT n)
b)
    no' Int
i (App AppStatus n
_ TT n
f TT n
a) = do Int -> TT n -> m ()
no' Int
i TT n
f; Int -> TT n -> m ()
no' Int
i TT n
a
    no' Int
i (Proj TT n
x Int
_) = Int -> TT n -> m ()
no' Int
i TT n
x
    no' Int
i TT n
_ = () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Returns true if V 0 and bound name n do not occur in the term
noOccurrence :: Eq n => n -> TT n -> Bool
noOccurrence :: forall n. Eq n => n -> TT n -> Bool
noOccurrence n
n TT n
t = Int -> TT n -> Bool
no' Int
0 TT n
t
  where
    no' :: Int -> TT n -> Bool
no' Int
i (V Int
x) = Bool -> Bool
not (Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
x)
    no' Int
i (P NameType
Bound n
x TT n
_) = Bool -> Bool
not (n
n n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
x)
    no' Int
i (Bind n
n Binder (TT n)
b TT n
sc) = Int -> Binder (TT n) -> Bool
noB' Int
i Binder (TT n)
b Bool -> Bool -> Bool
&& Int -> TT n -> Bool
no' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) TT n
sc
       where noB' :: Int -> Binder (TT n) -> Bool
noB' Int
i (Let RigCount
c TT n
t TT n
v) = Int -> TT n -> Bool
no' Int
i TT n
t Bool -> Bool -> Bool
&& Int -> TT n -> Bool
no' Int
i TT n
v
             noB' Int
i (Guess TT n
t TT n
v) = Int -> TT n -> Bool
no' Int
i TT n
t Bool -> Bool -> Bool
&& Int -> TT n -> Bool
no' Int
i TT n
v
             noB' Int
i Binder (TT n)
b = Int -> TT n -> Bool
no' Int
i (Binder (TT n) -> TT n
forall b. Binder b -> b
binderTy Binder (TT n)
b)
    no' Int
i (App AppStatus n
_ TT n
f TT n
a) = Int -> TT n -> Bool
no' Int
i TT n
f Bool -> Bool -> Bool
&& Int -> TT n -> Bool
no' Int
i TT n
a
    no' Int
i (Proj TT n
x Int
_) = Int -> TT n -> Bool
no' Int
i TT n
x
    no' Int
i TT n
_ = Bool
True

-- | Returns all names used free in the term
freeNames :: Eq n => TT n -> [n]
freeNames :: forall n. Eq n => TT n -> [n]
freeNames TT n
t = [n] -> [n]
forall a. Eq a => [a] -> [a]
nub ([n] -> [n]) -> [n] -> [n]
forall a b. (a -> b) -> a -> b
$ TT n -> [n]
forall n. Eq n => TT n -> [n]
freeNames' TT n
t
  where
    freeNames' :: TT a -> [a]
freeNames' (P NameType
_ a
n TT a
_) = [a
n]
    freeNames' (Bind a
n (Let RigCount
c TT a
t TT a
v) TT a
sc) = TT a -> [a]
freeNames' TT a
v [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ (TT a -> [a]
freeNames' TT a
sc [a] -> [a] -> [a]
forall a. Eq a => [a] -> [a] -> [a]
\\ [a
n])
                                            [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ TT a -> [a]
freeNames' TT a
t
    freeNames' (Bind a
n Binder (TT a)
b TT a
sc) = TT a -> [a]
freeNames' (Binder (TT a) -> TT a
forall b. Binder b -> b
binderTy Binder (TT a)
b) [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ (TT a -> [a]
freeNames' TT a
sc [a] -> [a] -> [a]
forall a. Eq a => [a] -> [a] -> [a]
\\ [a
n])
    freeNames' (App AppStatus a
_ TT a
f TT a
a) = TT a -> [a]
freeNames' TT a
f [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ TT a -> [a]
freeNames' TT a
a
    freeNames' (Proj TT a
x Int
i) = TT a -> [a]
freeNames' TT a
x
    freeNames' TT a
_ = []

-- | Return the arity of a (normalised) type
arity :: TT n -> Int
arity :: forall n. TT n -> Int
arity (Bind n
n (Pi RigCount
_ Maybe ImplicitInfo
_ TT n
t TT n
_) TT n
sc) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TT n -> Int
forall n. TT n -> Int
arity TT n
sc
arity TT n
_ = Int
0

-- | Deconstruct an application; returns the function and a list of arguments
unApply :: TT n -> (TT n, [TT n])
unApply :: forall n. TT n -> (TT n, [TT n])
unApply TT n
t = [TT n] -> TT n -> (TT n, [TT n])
forall {n}. [TT n] -> TT n -> (TT n, [TT n])
ua [] TT n
t where
    ua :: [TT n] -> TT n -> (TT n, [TT n])
ua [TT n]
args (App AppStatus n
_ TT n
f TT n
a) = [TT n] -> TT n -> (TT n, [TT n])
ua (TT n
aTT n -> [TT n] -> [TT n]
forall a. a -> [a] -> [a]
:[TT n]
args) TT n
f
    ua [TT n]
args TT n
t         = (TT n
t, [TT n]
args)

-- | Returns a term representing the application of the first argument
-- (a function) to every element of the second argument.
mkApp :: TT n -> [TT n] -> TT n
mkApp :: forall n. TT n -> [TT n] -> TT n
mkApp TT n
f [] = TT n
f
mkApp TT n
f (TT n
a:[TT n]
as) = TT n -> [TT n] -> TT n
forall n. TT n -> [TT n] -> TT n
mkApp (AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
forall n. AppStatus n
MaybeHoles TT n
f TT n
a) [TT n]
as

unList :: Term -> Maybe [Term]
unList :: TT Name -> Maybe [TT Name]
unList TT Name
tm = case TT Name -> (TT Name, [TT Name])
forall n. TT n -> (TT n, [TT n])
unApply TT Name
tm of
              (TT Name
nil, [TT Name
_]) -> [TT Name] -> Maybe [TT Name]
forall a. a -> Maybe a
Just []
              (TT Name
cons, ([TT Name
_, TT Name
x, TT Name
xs])) ->
                  do [TT Name]
rest <- TT Name -> Maybe [TT Name]
unList TT Name
xs
                     [TT Name] -> Maybe [TT Name]
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ([TT Name] -> Maybe [TT Name]) -> [TT Name] -> Maybe [TT Name]
forall a b. (a -> b) -> a -> b
$ TT Name
xTT Name -> [TT Name] -> [TT Name]
forall a. a -> [a] -> [a]
:[TT Name]
rest
              (TT Name
f, [TT Name]
args) -> Maybe [TT Name]
forall a. Maybe a
Nothing

-- | Hard-code a heuristic maximum term size, to prevent attempts to
-- serialize or force infinite or just gigantic terms
termSmallerThan :: Int -> Term -> Bool
termSmallerThan :: Int -> TT Name -> Bool
termSmallerThan Int
x TT Name
tm | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 =  Bool
False
termSmallerThan Int
x (P NameType
_ Name
_ TT Name
ty) = Int -> TT Name -> Bool
termSmallerThan (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) TT Name
ty
termSmallerThan Int
x (Bind Name
_ Binder (TT Name)
_ TT Name
tm) = Int -> TT Name -> Bool
termSmallerThan (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) TT Name
tm
termSmallerThan Int
x (App AppStatus Name
_ TT Name
f TT Name
a) = Int -> TT Name -> Bool
termSmallerThan (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) TT Name
f Bool -> Bool -> Bool
&& Int -> TT Name -> Bool
termSmallerThan (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) TT Name
a
termSmallerThan Int
x (Proj TT Name
tm Int
_) = Int -> TT Name -> Bool
termSmallerThan (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) TT Name
tm
termSmallerThan Int
x (V Int
i) = Bool
True
termSmallerThan Int
x (Constant Const
c) = Bool
True
termSmallerThan Int
x TT Name
Erased = Bool
True
termSmallerThan Int
x TT Name
Impossible = Bool
True
termSmallerThan Int
x (Inferred TT Name
t) = Int -> TT Name -> Bool
termSmallerThan Int
x TT Name
t
termSmallerThan Int
x (TType UExp
u) = Bool
True
termSmallerThan Int
x (UType Universe
u) = Bool
True


-- | Cast a 'TT' term to a 'Raw' value, discarding universe information and
-- the types of named references and replacing all de Bruijn indices
-- with the corresponding name. It is an error if there are free de
-- Bruijn indices.
forget :: TT Name -> Raw
forget :: TT Name -> Raw
forget TT Name
tm = [Name] -> TT Name -> Raw
forgetEnv [] TT Name
tm

safeForget :: TT Name -> Maybe Raw
safeForget :: TT Name -> Maybe Raw
safeForget TT Name
tm = [Name] -> TT Name -> Maybe Raw
safeForgetEnv [] TT Name
tm

forgetEnv :: [Name] -> TT Name -> Raw
forgetEnv :: [Name] -> TT Name -> Raw
forgetEnv [Name]
env TT Name
tm = case [Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
tm of
                     Just Raw
t' -> Raw
t'
                     Maybe Raw
Nothing -> String -> Raw
forall a. HasCallStack => String -> a
error (String -> Raw) -> String -> Raw
forall a b. (a -> b) -> a -> b
$ String
"Scope error in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TT Name -> String
forall a. Show a => a -> String
show TT Name
tm String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Name] -> String
forall a. Show a => a -> String
show [Name]
env


safeForgetEnv :: [Name] -> TT Name -> Maybe Raw
safeForgetEnv :: [Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env (P NameType
_ Name
n TT Name
_) = Raw -> Maybe Raw
forall a. a -> Maybe a
Just (Raw -> Maybe Raw) -> Raw -> Maybe Raw
forall a b. (a -> b) -> a -> b
$ Name -> Raw
Var Name
n
safeForgetEnv [Name]
env (V Int
i) | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< [Name] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Name]
env = Raw -> Maybe Raw
forall a. a -> Maybe a
Just (Raw -> Maybe Raw) -> Raw -> Maybe Raw
forall a b. (a -> b) -> a -> b
$ Name -> Raw
Var ([Name]
env [Name] -> Int -> Name
forall a. HasCallStack => [a] -> Int -> a
!! Int
i)
                        | Bool
otherwise = Maybe Raw
forall a. Maybe a
Nothing
safeForgetEnv [Name]
env (Bind Name
n Binder (TT Name)
b TT Name
sc)
     = do let n' :: Name
n' = Name -> [Name] -> Name
uniqueName Name
n [Name]
env
          Binder Raw
b' <- [Name] -> Binder (TT Name) -> Maybe (Binder Raw)
safeForgetEnvB [Name]
env Binder (TT Name)
b
          Raw
sc' <- [Name] -> TT Name -> Maybe Raw
safeForgetEnv (Name
n'Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) TT Name
sc
          Raw -> Maybe Raw
forall a. a -> Maybe a
Just (Raw -> Maybe Raw) -> Raw -> Maybe Raw
forall a b. (a -> b) -> a -> b
$ Name -> Binder Raw -> Raw -> Raw
RBind Name
n' Binder Raw
b' Raw
sc'
  where safeForgetEnvB :: [Name] -> Binder (TT Name) -> Maybe (Binder Raw)
safeForgetEnvB [Name]
env (Let RigCount
c TT Name
t TT Name
v) = (Raw -> Raw -> Binder Raw)
-> Maybe Raw -> Maybe Raw -> Maybe (Binder Raw)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (RigCount -> Raw -> Raw -> Binder Raw
forall b. RigCount -> b -> b -> Binder b
Let RigCount
c) ([Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
t)
                                                        ([Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
v)
        safeForgetEnvB [Name]
env (Guess TT Name
t TT Name
v) = (Raw -> Raw -> Binder Raw)
-> Maybe Raw -> Maybe Raw -> Maybe (Binder Raw)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Raw -> Raw -> Binder Raw
forall b. b -> b -> Binder b
Guess ([Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
t)
                                                      ([Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
v)
        safeForgetEnvB [Name]
env Binder (TT Name)
b = do Raw
ty' <- [Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env (Binder (TT Name) -> TT Name
forall b. Binder b -> b
binderTy Binder (TT Name)
b)
                                  Binder Raw -> Maybe (Binder Raw)
forall a. a -> Maybe a
Just (Binder Raw -> Maybe (Binder Raw))
-> Binder Raw -> Maybe (Binder Raw)
forall a b. (a -> b) -> a -> b
$ (TT Name -> Raw) -> Binder (TT Name) -> Binder Raw
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\TT Name
_ -> Raw
ty') Binder (TT Name)
b
safeForgetEnv [Name]
env (App AppStatus Name
_ TT Name
f TT Name
a) = (Raw -> Raw -> Raw) -> Maybe Raw -> Maybe Raw -> Maybe Raw
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Raw -> Raw -> Raw
RApp ([Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
f) ([Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
a)
safeForgetEnv [Name]
env (Constant Const
c) = Raw -> Maybe Raw
forall a. a -> Maybe a
Just (Raw -> Maybe Raw) -> Raw -> Maybe Raw
forall a b. (a -> b) -> a -> b
$ Const -> Raw
RConstant Const
c
safeForgetEnv [Name]
env (TType UExp
i) = Raw -> Maybe Raw
forall a. a -> Maybe a
Just Raw
RType
safeForgetEnv [Name]
env (UType Universe
u) = Raw -> Maybe Raw
forall a. a -> Maybe a
Just (Raw -> Maybe Raw) -> Raw -> Maybe Raw
forall a b. (a -> b) -> a -> b
$ Universe -> Raw
RUType Universe
u
safeForgetEnv [Name]
env TT Name
Erased    = Raw -> Maybe Raw
forall a. a -> Maybe a
Just (Raw -> Maybe Raw) -> Raw -> Maybe Raw
forall a b. (a -> b) -> a -> b
$ Const -> Raw
RConstant Const
Forgot
safeForgetEnv [Name]
env (Proj TT Name
tm Int
i) = String -> Maybe Raw
forall a. HasCallStack => String -> a
error String
"Don't know how to forget a projection"
safeForgetEnv [Name]
env TT Name
Impossible = String -> Maybe Raw
forall a. HasCallStack => String -> a
error String
"Don't know how to forget Impossible"
safeForgetEnv [Name]
env (Inferred TT Name
t) = [Name] -> TT Name -> Maybe Raw
safeForgetEnv [Name]
env TT Name
t

-- | Introduce a 'Bind' into the given term for each element of the
-- given list of (name, binder) pairs.
bindAll :: [(n, Binder (TT n))] -> TT n -> TT n
bindAll :: forall {n}. [(n, Binder (TT n))] -> TT n -> TT n
bindAll [] TT n
t = TT n
t
bindAll ((n
n, Binder (TT n)
b) : [(n, Binder (TT n))]
bs) TT n
t = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
n Binder (TT n)
b ([(n, Binder (TT n))] -> TT n -> TT n
forall {n}. [(n, Binder (TT n))] -> TT n -> TT n
bindAll [(n, Binder (TT n))]
bs TT n
t)

-- | Like 'bindAll', but the 'Binder's are 'TT' terms instead.
-- The first argument is a function to map @TT@ terms to @Binder@s.
-- This function might often be something like 'Lam', which directly
-- constructs a @Binder@ from a @TT@ term.
bindTyArgs :: (TT n -> Binder (TT n)) -> [(n, TT n)] -> TT n -> TT n
bindTyArgs :: forall n. (TT n -> Binder (TT n)) -> [(n, TT n)] -> TT n -> TT n
bindTyArgs TT n -> Binder (TT n)
b [(n, TT n)]
xs = [(n, Binder (TT n))] -> TT n -> TT n
forall {n}. [(n, Binder (TT n))] -> TT n -> TT n
bindAll (((n, TT n) -> (n, Binder (TT n)))
-> [(n, TT n)] -> [(n, Binder (TT n))]
forall a b. (a -> b) -> [a] -> [b]
map (\ (n
n, TT n
ty) -> (n
n, TT n -> Binder (TT n)
b TT n
ty)) [(n, TT n)]
xs)

-- | Return a list of pairs of the names of the outermost 'Pi'-bound
-- variables in the given term, together with their types.
getArgTys :: TT n -> [(n, TT n)]
getArgTys :: forall n. TT n -> [(n, TT n)]
getArgTys (Bind n
n (PVar RigCount
_ TT n
_) TT n
sc) = TT n -> [(n, TT n)]
forall n. TT n -> [(n, TT n)]
getArgTys TT n
sc
getArgTys (Bind n
n (PVTy TT n
_) TT n
sc) = TT n -> [(n, TT n)]
forall n. TT n -> [(n, TT n)]
getArgTys TT n
sc
getArgTys (Bind n
n (Pi RigCount
_ Maybe ImplicitInfo
_ TT n
t TT n
_) TT n
sc) = (n
n, TT n
t) (n, TT n) -> [(n, TT n)] -> [(n, TT n)]
forall a. a -> [a] -> [a]
: TT n -> [(n, TT n)]
forall n. TT n -> [(n, TT n)]
getArgTys TT n
sc
getArgTys TT n
_ = []

getRetTy :: TT n -> TT n
getRetTy :: forall n. TT n -> TT n
getRetTy (Bind n
n (PVar RigCount
_ TT n
_) TT n
sc) = TT n -> TT n
forall n. TT n -> TT n
getRetTy TT n
sc
getRetTy (Bind n
n (PVTy TT n
_) TT n
sc) = TT n -> TT n
forall n. TT n -> TT n
getRetTy TT n
sc
getRetTy (Bind n
n (Pi RigCount
_ Maybe ImplicitInfo
_ TT n
_ TT n
_) TT n
sc)   = TT n -> TT n
forall n. TT n -> TT n
getRetTy TT n
sc
getRetTy TT n
sc = TT n
sc

-- | As getRetTy but substitutes names for de Bruijn indices
substRetTy :: TT n -> TT n
substRetTy :: forall n. TT n -> TT n
substRetTy (Bind n
n (PVar RigCount
_ TT n
ty) TT n
sc) = TT n -> TT n
forall n. TT n -> TT n
substRetTy (TT n -> TT n -> TT n
forall n. TT n -> TT n -> TT n
substV (NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
Ref n
n TT n
ty) TT n
sc)
substRetTy (Bind n
n (PVTy TT n
ty) TT n
sc) = TT n -> TT n
forall n. TT n -> TT n
substRetTy (TT n -> TT n -> TT n
forall n. TT n -> TT n -> TT n
substV (NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
Ref n
n TT n
ty) TT n
sc)
substRetTy (Bind n
n (Pi RigCount
_ Maybe ImplicitInfo
_ TT n
ty TT n
_) TT n
sc) = TT n -> TT n
forall n. TT n -> TT n
substRetTy (TT n -> TT n -> TT n
forall n. TT n -> TT n -> TT n
substV (NameType -> n -> TT n -> TT n
forall n. NameType -> n -> TT n -> TT n
P NameType
Ref n
n TT n
ty) TT n
sc)
substRetTy TT n
sc = TT n
sc


uniqueNameFrom :: [Name] -> [Name] -> Name
uniqueNameFrom :: [Name] -> [Name] -> Name
uniqueNameFrom []           [Name]
hs = Name -> [Name] -> Name
uniqueName (Name -> Name
nextName (String -> Name
sUN String
"x")) [Name]
hs
uniqueNameFrom (Name
s : [Name]
supply) [Name]
hs
       | Name
s Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
hs = [Name] -> [Name] -> Name
uniqueNameFrom [Name]
supply [Name]
hs
       | Bool
otherwise   = Name
s

uniqueName :: Name -> [Name] -> Name
uniqueName :: Name -> [Name] -> Name
uniqueName Name
n [Name]
hs | Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
hs = Name -> [Name] -> Name
uniqueName (Name -> Name
nextName Name
n) [Name]
hs
                | Bool
otherwise   = Name
n

uniqueNameSet :: Name -> Set Name -> Name
uniqueNameSet :: Name -> Set Name -> Name
uniqueNameSet Name
n Set Name
hs | Name
n Name -> Set Name -> Bool
forall a. Ord a => a -> Set a -> Bool
`member` Set Name
hs = Name -> Set Name -> Name
uniqueNameSet (Name -> Name
nextName Name
n) Set Name
hs
                   | Bool
otherwise   = Name
n

uniqueBinders :: [Name] -> TT Name -> TT Name
uniqueBinders :: [Name] -> TT Name -> TT Name
uniqueBinders [Name]
ns = Set Name -> TT Name -> TT Name
ubSet ([Name] -> Set Name
forall a. Ord a => [a] -> Set a
fromList [Name]
ns) where
    ubSet :: Set Name -> TT Name -> TT Name
ubSet Set Name
ns (Bind Name
n Binder (TT Name)
b TT Name
sc)
        = let n' :: Name
n' = Name -> Set Name -> Name
uniqueNameSet Name
n Set Name
ns
              ns' :: Set Name
ns' = Name -> Set Name -> Set Name
forall a. Ord a => a -> Set a -> Set a
insert Name
n' Set Name
ns in
              Name -> Binder (TT Name) -> TT Name -> TT Name
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind Name
n' ((TT Name -> TT Name) -> Binder (TT Name) -> Binder (TT Name)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Set Name -> TT Name -> TT Name
ubSet Set Name
ns') Binder (TT Name)
b) (Set Name -> TT Name -> TT Name
ubSet Set Name
ns' TT Name
sc)
    ubSet Set Name
ns (App AppStatus Name
s TT Name
f TT Name
a) = AppStatus Name -> TT Name -> TT Name -> TT Name
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus Name
s (Set Name -> TT Name -> TT Name
ubSet Set Name
ns TT Name
f) (Set Name -> TT Name -> TT Name
ubSet Set Name
ns TT Name
a)
    ubSet Set Name
ns TT Name
t = TT Name
t


nextName :: Name -> Name
nextName :: Name -> Name
nextName (NS Name
x [Text]
s)    = Name -> [Text] -> Name
NS (Name -> Name
nextName Name
x) [Text]
s
nextName (MN Int
i Text
n)    = Int -> Text -> Name
MN (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) Text
n
nextName (UN Text
x) = let (Text
num', Text
nm') = (Char -> Bool) -> Text -> (Text, Text)
T.span Char -> Bool
isDigit (Text -> Text
T.reverse Text
x)
                      nm :: Text
nm = Text -> Text
T.reverse Text
nm'
                      num :: Integer
num = Text -> Integer
forall {a}. (Read a, Num a) => Text -> a
readN (Text -> Text
T.reverse Text
num') in
                          Text -> Name
UN (Text
nm Text -> Text -> Text
`T.append` String -> Text
txt (Integer -> String
forall a. Show a => a -> String
show (Integer
numInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1)))
  where
    readN :: Text -> a
readN Text
x | Bool -> Bool
not (Text -> Bool
T.null Text
x) = String -> a
forall a. Read a => String -> a
read (Text -> String
T.unpack Text
x)
    readN Text
x = a
0
nextName (SN SpecialName
x) = SpecialName -> Name
SN (SpecialName -> SpecialName
nextName' SpecialName
x)
  where
    nextName' :: SpecialName -> SpecialName
nextName' (WhereN Int
i Name
f Name
x) = Int -> Name -> Name -> SpecialName
WhereN Int
i Name
f (Name -> Name
nextName Name
x)
    nextName' (WithN Int
i Name
n) = Int -> Name -> SpecialName
WithN Int
i (Name -> Name
nextName Name
n)
    nextName' (ImplementationN Name
n [Text]
ns) = Name -> [Text] -> SpecialName
ImplementationN (Name -> Name
nextName Name
n) [Text]
ns
    nextName' (ParentN Name
n Text
ns) = Name -> Text -> SpecialName
ParentN (Name -> Name
nextName Name
n) Text
ns
    nextName' (CaseN FC'
fc Name
n) = FC' -> Name -> SpecialName
CaseN FC'
fc (Name -> Name
nextName Name
n)
    nextName' (MethodN Name
n) = Name -> SpecialName
MethodN (Name -> Name
nextName Name
n)
    nextName' (ImplementationCtorN Name
n) = Name -> SpecialName
ImplementationCtorN (Name -> Name
nextName Name
n)
    nextName' (MetaN Name
parent Name
meta) = Name -> Name -> SpecialName
MetaN Name
parent (Name -> Name
nextName Name
meta)
nextName (SymRef Int
i) = String -> Name
forall a. HasCallStack => String -> a
error String
"Can't generate a name from a symbol reference"

type Term = TT Name
type Type = Term

type Env  = EnvTT Name

-- | an environment with de Bruijn indices 'normalised' so that they all refer to
-- this environment

newtype WkEnvTT n = Wk (EnvTT n)
type WkEnv = WkEnvTT Name

instance (Eq n, Show n) => Show (TT n) where
    show :: TT n -> String
show TT n
t = EnvTT n -> TT n -> String
forall n. (Eq n, Show n) => EnvTT n -> TT n -> String
showEnv [] TT n
t

itBitsName :: NativeTy -> String
itBitsName NativeTy
IT8 = String
"Bits8"
itBitsName NativeTy
IT16 = String
"Bits16"
itBitsName NativeTy
IT32 = String
"Bits32"
itBitsName NativeTy
IT64 = String
"Bits64"

instance Show Const where
    show :: Const -> String
show (I Int
i) = Int -> String
forall a. Show a => a -> String
show Int
i
    show (BI Integer
i) = Integer -> String
forall a. Show a => a -> String
show Integer
i
    show (Fl Double
f) = Double -> String
forall a. Show a => a -> String
show Double
f
    show (Ch Char
c) = Char -> String
forall a. Show a => a -> String
show Char
c
    show (Str String
s) = ShowS
forall a. Show a => a -> String
show String
s
    show (B8 Word8
x) = Word8 -> String
forall a. Show a => a -> String
show Word8
x
    show (B16 Word16
x) = Word16 -> String
forall a. Show a => a -> String
show Word16
x
    show (B32 Word32
x) = Word32 -> String
forall a. Show a => a -> String
show Word32
x
    show (B64 Word64
x) = Word64 -> String
forall a. Show a => a -> String
show Word64
x
    show (AType ArithTy
ATFloat) = String
"Double"
    show (AType (ATInt IntTy
ITBig)) = String
"Integer"
    show (AType (ATInt IntTy
ITNative)) = String
"Int"
    show (AType (ATInt IntTy
ITChar)) = String
"Char"
    show (AType (ATInt (ITFixed NativeTy
it))) = NativeTy -> String
itBitsName NativeTy
it
    show Const
TheWorld = String
"prim__TheWorld"
    show Const
WorldType = String
"prim__WorldType"
    show Const
StrType = String
"String"
    show Const
VoidType = String
"Void"
    show Const
Forgot = String
"Forgot"

showEnv :: (Eq n, Show n) => EnvTT n -> TT n -> String
showEnv :: forall n. (Eq n, Show n) => EnvTT n -> TT n -> String
showEnv EnvTT n
env TT n
t = EnvTT n -> TT n -> Bool -> String
forall {a}.
(Show a, Eq a) =>
[(a, RigCount, Binder (TT a))] -> TT a -> Bool -> String
showEnv' EnvTT n
env TT n
t Bool
False
showEnvDbg :: [(a, RigCount, Binder (TT a))] -> TT a -> String
showEnvDbg [(a, RigCount, Binder (TT a))]
env TT a
t = [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> String
forall {a}.
(Show a, Eq a) =>
[(a, RigCount, Binder (TT a))] -> TT a -> Bool -> String
showEnv' [(a, RigCount, Binder (TT a))]
env TT a
t Bool
True

prettyEnv :: Env -> Term -> Doc OutputAnnotation
prettyEnv :: Env -> TT Name -> Doc OutputAnnotation
prettyEnv Env
env TT Name
t = Env -> TT Name -> Bool -> Doc OutputAnnotation
forall {a} {a}.
(Show a, Pretty a a, Pretty NameType a, Pretty Const a, Eq a) =>
[(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettyEnv' Env
env TT Name
t Bool
False
  where
    prettyEnv' :: [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettyEnv' [(a, RigCount, Binder (TT a))]
env TT a
t Bool
dbg = Integer -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
forall {t} {a} {a}.
(Num t, Show a, Ord t, Pretty a a, Pretty NameType a,
 Pretty Const a, Eq a) =>
t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe Integer
10 [(a, RigCount, Binder (TT a))]
env TT a
t Bool
dbg

    bracket :: a -> a -> Doc a -> Doc a
bracket a
outer a
inner Doc a
p
      | a
inner a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
outer = Doc a
forall a. Doc a
lparen Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> Doc a
p Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> Doc a
forall a. Doc a
rparen
      | Bool
otherwise     = Doc a
p

    prettySe :: t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
p [(a, RigCount, Binder (TT a))]
env (P NameType
nt a
n TT a
t) Bool
debug =
      a -> Doc a
forall a ty. Pretty a ty => a -> Doc ty
pretty a
n Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+>
        if Bool
debug then
          Doc a
forall a. Doc a
lbracket Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> NameType -> Doc a
forall a ty. Pretty a ty => a -> Doc ty
pretty NameType
nt Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> Doc a
forall a. Doc a
colon Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
10 [(a, RigCount, Binder (TT a))]
env TT a
t Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> Doc a
forall a. Doc a
rbracket
        else
          Doc a
forall a. Doc a
empty
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (V Int
i) Bool
debug
      | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< [(a, RigCount, Binder (TT a))] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(a, RigCount, Binder (TT a))]
env =
        if Bool
debug then
          String -> Doc a
forall a. String -> Doc a
text (String -> Doc a)
-> ((a, RigCount, Binder (TT a)) -> String)
-> (a, RigCount, Binder (TT a))
-> Doc a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show (a -> String)
-> ((a, RigCount, Binder (TT a)) -> a)
-> (a, RigCount, Binder (TT a))
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, RigCount, Binder (TT a)) -> a
forall {a} {b} {c}. (a, b, c) -> a
fstEnv ((a, RigCount, Binder (TT a)) -> Doc a)
-> (a, RigCount, Binder (TT a)) -> Doc a
forall a b. (a -> b) -> a -> b
$ [(a, RigCount, Binder (TT a))]
env[(a, RigCount, Binder (TT a))]
-> Int -> (a, RigCount, Binder (TT a))
forall a. HasCallStack => [a] -> Int -> a
!!Int
i
        else
          Doc a
forall a. Doc a
lbracket Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc a
forall a. String -> Doc a
text (Int -> String
forall a. Show a => a -> String
show Int
i) Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> Doc a
forall a. Doc a
rbracket
      | Bool
otherwise      = String -> Doc a
forall a. String -> Doc a
text String
"unbound" Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc a
forall a. String -> Doc a
text (Int -> String
forall a. Show a => a -> String
show Int
i) Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc a
forall a. String -> Doc a
text String
"!"
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (Bind a
n b :: Binder (TT a)
b@(Pi RigCount
_ Maybe ImplicitInfo
_ TT a
t TT a
_) TT a
sc) Bool
debug
      | a -> TT a -> Bool
forall n. Eq n => n -> TT n -> Bool
noOccurrence a
n TT a
sc Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
debug =
          t -> t -> Doc a -> Doc a
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket t
p t
2 (Doc a -> Doc a) -> Doc a -> Doc a
forall a b. (a -> b) -> a -> b
$ [(a, RigCount, Binder (TT a))]
-> a -> Binder (TT a) -> Bool -> Doc a
prettySb [(a, RigCount, Binder (TT a))]
env a
n Binder (TT a)
b Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
10 ((a
n, RigCount
Rig0, Binder (TT a)
b)(a, RigCount, Binder (TT a))
-> [(a, RigCount, Binder (TT a))] -> [(a, RigCount, Binder (TT a))]
forall a. a -> [a] -> [a]
:[(a, RigCount, Binder (TT a))]
env) TT a
sc Bool
debug
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (Bind a
n Binder (TT a)
b TT a
sc) Bool
debug =
      t -> t -> Doc a -> Doc a
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket t
p t
2 (Doc a -> Doc a) -> Doc a -> Doc a
forall a b. (a -> b) -> a -> b
$ [(a, RigCount, Binder (TT a))]
-> a -> Binder (TT a) -> Bool -> Doc a
prettySb [(a, RigCount, Binder (TT a))]
env a
n Binder (TT a)
b Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
10 ((a
n, RigCount
Rig0, Binder (TT a)
b)(a, RigCount, Binder (TT a))
-> [(a, RigCount, Binder (TT a))] -> [(a, RigCount, Binder (TT a))]
forall a. a -> [a] -> [a]
:[(a, RigCount, Binder (TT a))]
env) TT a
sc Bool
debug
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (App AppStatus a
_ TT a
f TT a
a) Bool
debug =
      t -> t -> Doc a -> Doc a
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket t
p t
1 (Doc a -> Doc a) -> Doc a -> Doc a
forall a b. (a -> b) -> a -> b
$ t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
1 [(a, RigCount, Binder (TT a))]
env TT a
f Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
0 [(a, RigCount, Binder (TT a))]
env TT a
a Bool
debug
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (Proj TT a
x Int
i) Bool
debug =
      t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
1 [(a, RigCount, Binder (TT a))]
env TT a
x Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc a
forall a. String -> Doc a
text (String
"!" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i)
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (Constant Const
c) Bool
debug = Const -> Doc a
forall a ty. Pretty a ty => a -> Doc ty
pretty Const
c
    prettySe t
p [(a, RigCount, Binder (TT a))]
env TT a
Erased Bool
debug = String -> Doc a
forall a. String -> Doc a
text String
"[_]"
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (TType UExp
i) Bool
debug = String -> Doc a
forall a. String -> Doc a
text String
"Type" Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> (String -> Doc a
forall a. String -> Doc a
text (String -> Doc a) -> (UExp -> String) -> UExp -> Doc a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UExp -> String
forall a. Show a => a -> String
show (UExp -> Doc a) -> UExp -> Doc a
forall a b. (a -> b) -> a -> b
$ UExp
i)
    prettySe t
p [(a, RigCount, Binder (TT a))]
env TT a
Impossible Bool
debug = String -> Doc a
forall a. String -> Doc a
text String
"Impossible"
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (Inferred TT a
tm) Bool
debug = String -> Doc a
forall a. String -> Doc a
text String
"<" Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
p [(a, RigCount, Binder (TT a))]
env TT a
tm Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc a
forall a. String -> Doc a
text String
">"
    prettySe t
p [(a, RigCount, Binder (TT a))]
env (UType Universe
u) Bool
debug = String -> Doc a
forall a. String -> Doc a
text (Universe -> String
forall a. Show a => a -> String
show Universe
u)

    -- Render a `Binder` and its name
    prettySb :: [(a, RigCount, Binder (TT a))]
-> a -> Binder (TT a) -> Bool -> Doc a
prettySb [(a, RigCount, Binder (TT a))]
env a
n (Lam RigCount
_ TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"λ" String
"=>" a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (Hole TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"?defer" String
"." a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (GHole Int
_ [Name]
_ TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"?gdefer" String
"." a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (Pi RigCount
Rig0 Maybe ImplicitInfo
_ TT a
t TT a
_) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"(" String
") ->" a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (Pi RigCount
Rig1 Maybe ImplicitInfo
_ TT a
t TT a
_) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"(" String
") -o" a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (Pi RigCount
RigW Maybe ImplicitInfo
_ TT a
t TT a
_) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"(" String
") ->" a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (PVar RigCount
Rig1 TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"pat 1 " String
"." a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (PVar RigCount
_ TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"pat" String
"." a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (PVTy TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
"pty" String
"." a
n TT a
t
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (Let RigCount
Rig1 TT a
t TT a
v) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> Bool -> Doc a
prettyBv [(a, RigCount, Binder (TT a))]
env String
"let 1 " String
"in" a
n TT a
t TT a
v
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (Let RigCount
_ TT a
t TT a
v) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> Bool -> Doc a
prettyBv [(a, RigCount, Binder (TT a))]
env String
"let" String
"in" a
n TT a
t TT a
v
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (NLet TT a
t TT a
v) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> Bool -> Doc a
prettyBv [(a, RigCount, Binder (TT a))]
env String
"nlet" String
"in" a
n TT a
t TT a
v
    prettySb [(a, RigCount, Binder (TT a))]
env a
n (Guess TT a
t TT a
v) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> Bool -> Doc a
prettyBv [(a, RigCount, Binder (TT a))]
env String
"??" String
"in" a
n TT a
t TT a
v

    -- Use `op` and `sc` to delimit `n` (a binding name) and its type
    -- declaration
    -- e.g. "λx : Int =>" for the Lam case
    prettyB :: [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> Bool -> Doc a
prettyB [(a, RigCount, Binder (TT a))]
env String
op String
sc a
n TT a
t Bool
debug =
      String -> Doc a
forall a. String -> Doc a
text String
op Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> a -> Doc a
forall a ty. Pretty a ty => a -> Doc ty
pretty a
n Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> Doc a
forall a. Doc a
colon Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
10 [(a, RigCount, Binder (TT a))]
env TT a
t Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc a
forall a. String -> Doc a
text String
sc

    -- Like `prettyB`, but handle the bindings that have values in addition
    -- to names and types
    prettyBv :: [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> Bool -> Doc a
prettyBv [(a, RigCount, Binder (TT a))]
env String
op String
sc a
n TT a
t TT a
v Bool
debug =
      String -> Doc a
forall a. String -> Doc a
text String
op Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> a -> Doc a
forall a ty. Pretty a ty => a -> Doc ty
pretty a
n Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> Doc a
forall a. Doc a
colon Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
10 [(a, RigCount, Binder (TT a))]
env TT a
t Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc a
forall a. String -> Doc a
text String
"=" Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<+>
        t -> [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> Doc a
prettySe t
10 [(a, RigCount, Binder (TT a))]
env TT a
v Bool
debug Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc a
forall a. String -> Doc a
text String
sc


showEnv' :: [(a, RigCount, Binder (TT a))] -> TT a -> Bool -> String
showEnv' [(a, RigCount, Binder (TT a))]
env TT a
t Bool
dbg = Integer -> [(a, RigCount, Binder (TT a))] -> TT a -> String
forall {a} {t}.
(Show a, Num t, Ord t, Eq a) =>
t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se Integer
10 [(a, RigCount, Binder (TT a))]
env TT a
t where
    se :: t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
p [(a, RigCount, Binder (TT a))]
env (P NameType
nt a
n TT a
t) = a -> String
forall a. Show a => a -> String
show a
n
                            String -> ShowS
forall a. [a] -> [a] -> [a]
++ if Bool
dbg then String
"{" String -> ShowS
forall a. [a] -> [a] -> [a]
++ NameType -> String
forall a. Show a => a -> String
show NameType
nt String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" : " String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
10 [(a, RigCount, Binder (TT a))]
env TT a
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"}" else String
""
    se t
p [(a, RigCount, Binder (TT a))]
env (V Int
i) | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< [(a, RigCount, Binder (TT a))] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(a, RigCount, Binder (TT a))]
env Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0
                                    = (a -> String
forall a. Show a => a -> String
show (a -> String) -> a -> String
forall a b. (a -> b) -> a -> b
$ (a, RigCount, Binder (TT a)) -> a
forall {a} {b} {c}. (a, b, c) -> a
fstEnv ((a, RigCount, Binder (TT a)) -> a)
-> (a, RigCount, Binder (TT a)) -> a
forall a b. (a -> b) -> a -> b
$ [(a, RigCount, Binder (TT a))]
env[(a, RigCount, Binder (TT a))]
-> Int -> (a, RigCount, Binder (TT a))
forall a. HasCallStack => [a] -> Int -> a
!!Int
i) String -> ShowS
forall a. [a] -> [a] -> [a]
++
                                      if Bool
dbg then String
"{" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"}" else String
""
                   | Bool
otherwise = String
"!!V " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"!!"
    se t
p [(a, RigCount, Binder (TT a))]
env (Bind a
n b :: Binder (TT a)
b@(Pi RigCount
rig (Just ImplicitInfo
_) TT a
t TT a
k) TT a
sc)
         = t -> t -> ShowS
forall {a}. Ord a => a -> a -> ShowS
bracket t
p t
2 ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [(a, RigCount, Binder (TT a))] -> a -> Binder (TT a) -> String
sb [(a, RigCount, Binder (TT a))]
env a
n Binder (TT a)
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
10 ((a
n, RigCount
rig, Binder (TT a)
b)(a, RigCount, Binder (TT a))
-> [(a, RigCount, Binder (TT a))] -> [(a, RigCount, Binder (TT a))]
forall a. a -> [a] -> [a]
:[(a, RigCount, Binder (TT a))]
env) TT a
sc
    se t
p [(a, RigCount, Binder (TT a))]
env (Bind a
n b :: Binder (TT a)
b@(Pi RigCount
rig Maybe ImplicitInfo
_ TT a
t TT a
k) TT a
sc)
        | a -> TT a -> Bool
forall n. Eq n => n -> TT n -> Bool
noOccurrence a
n TT a
sc Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
dbg = t -> t -> ShowS
forall {a}. Ord a => a -> a -> ShowS
bracket t
p t
2 ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
1 [(a, RigCount, Binder (TT a))]
env TT a
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ RigCount -> String
arrow RigCount
rig String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
10 ((a
n,RigCount
Rig0,Binder (TT a)
b)(a, RigCount, Binder (TT a))
-> [(a, RigCount, Binder (TT a))] -> [(a, RigCount, Binder (TT a))]
forall a. a -> [a] -> [a]
:[(a, RigCount, Binder (TT a))]
env) TT a
sc
       where arrow :: RigCount -> String
arrow RigCount
Rig0 = String
" 0-> "
             arrow RigCount
Rig1 = String
" -o "
             arrow RigCount
RigW = String
" -> "
    se t
p [(a, RigCount, Binder (TT a))]
env (Bind a
n Binder (TT a)
b TT a
sc) = t -> t -> ShowS
forall {a}. Ord a => a -> a -> ShowS
bracket t
p t
2 ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [(a, RigCount, Binder (TT a))] -> a -> Binder (TT a) -> String
sb [(a, RigCount, Binder (TT a))]
env a
n Binder (TT a)
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
10 ((a
n,RigCount
Rig0,Binder (TT a)
b)(a, RigCount, Binder (TT a))
-> [(a, RigCount, Binder (TT a))] -> [(a, RigCount, Binder (TT a))]
forall a. a -> [a] -> [a]
:[(a, RigCount, Binder (TT a))]
env) TT a
sc
    se t
p [(a, RigCount, Binder (TT a))]
env (App AppStatus a
_ TT a
f TT a
a) = t -> t -> ShowS
forall {a}. Ord a => a -> a -> ShowS
bracket t
p t
1 ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
1 [(a, RigCount, Binder (TT a))]
env TT a
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
0 [(a, RigCount, Binder (TT a))]
env TT a
a
    se t
p [(a, RigCount, Binder (TT a))]
env (Proj TT a
x Int
i) = t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
1 [(a, RigCount, Binder (TT a))]
env TT a
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"!" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    se t
p [(a, RigCount, Binder (TT a))]
env (Constant Const
c) = Const -> String
forall a. Show a => a -> String
show Const
c
    se t
p [(a, RigCount, Binder (TT a))]
env TT a
Erased = String
"[__]"
    se t
p [(a, RigCount, Binder (TT a))]
env TT a
Impossible = String
"[impossible]"
    se t
p [(a, RigCount, Binder (TT a))]
env (Inferred TT a
t) = String
"<" String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
p [(a, RigCount, Binder (TT a))]
env TT a
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
">"
    se t
p [(a, RigCount, Binder (TT a))]
env (TType UExp
i) = String
"Type " String -> ShowS
forall a. [a] -> [a] -> [a]
++ UExp -> String
forall a. Show a => a -> String
show UExp
i
    se t
p [(a, RigCount, Binder (TT a))]
env (UType Universe
u) = Universe -> String
forall a. Show a => a -> String
show Universe
u

    sb :: [(a, RigCount, Binder (TT a))] -> a -> Binder (TT a) -> String
sb [(a, RigCount, Binder (TT a))]
env a
n (Lam RigCount
Rig1 TT a
t)  = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"\\ 1 " String
" => " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (Lam RigCount
_ TT a
t)  = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"\\ " String
" => " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (Hole TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"? " String
". " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (GHole Int
i [Name]
ns TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"?defer " String
". " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (Pi RigCount
Rig1 (Just ImplicitInfo
_) TT a
t TT a
_)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"{" String
"} -o " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (Pi RigCount
_ (Just ImplicitInfo
_) TT a
t TT a
_)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"{" String
"} -> " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (Pi RigCount
Rig1 Maybe ImplicitInfo
_ TT a
t TT a
_)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"(" String
") -0 " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (Pi RigCount
_ Maybe ImplicitInfo
_ TT a
t TT a
_)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"(" String
") -> " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (PVar RigCount
Rig0 TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"pat 0 " String
". " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (PVar RigCount
Rig1 TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"pat 1 " String
". " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (PVar RigCount
_ TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"pat " String
". " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (PVTy TT a
t) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
"pty " String
". " a
n TT a
t
    sb [(a, RigCount, Binder (TT a))]
env a
n (Let RigCount
Rig0 TT a
t TT a
v)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> String
showbv [(a, RigCount, Binder (TT a))]
env String
"let 0 " String
" in " a
n TT a
t TT a
v
    sb [(a, RigCount, Binder (TT a))]
env a
n (Let RigCount
Rig1 TT a
t TT a
v)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> String
showbv [(a, RigCount, Binder (TT a))]
env String
"let 1 " String
" in " a
n TT a
t TT a
v
    sb [(a, RigCount, Binder (TT a))]
env a
n (Let RigCount
_ TT a
t TT a
v)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> String
showbv [(a, RigCount, Binder (TT a))]
env String
"let " String
" in " a
n TT a
t TT a
v
    sb [(a, RigCount, Binder (TT a))]
env a
n (NLet TT a
t TT a
v)   = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> String
showbv [(a, RigCount, Binder (TT a))]
env String
"nlet " String
" in " a
n TT a
t TT a
v
    sb [(a, RigCount, Binder (TT a))]
env a
n (Guess TT a
t TT a
v) = [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> String
showbv [(a, RigCount, Binder (TT a))]
env String
"?? " String
" in " a
n TT a
t TT a
v

    showb :: [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> String
showb [(a, RigCount, Binder (TT a))]
env String
op String
sc a
n TT a
t    = String
op String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" : " String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
10 [(a, RigCount, Binder (TT a))]
env TT a
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
sc
    showbv :: [(a, RigCount, Binder (TT a))]
-> String -> String -> a -> TT a -> TT a -> String
showbv [(a, RigCount, Binder (TT a))]
env String
op String
sc a
n TT a
t TT a
v = String
op String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" : " String -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
10 [(a, RigCount, Binder (TT a))]
env TT a
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" = " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                             t -> [(a, RigCount, Binder (TT a))] -> TT a -> String
se t
10 [(a, RigCount, Binder (TT a))]
env TT a
v String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
sc

    bracket :: a -> a -> ShowS
bracket a
outer a
inner String
str | a
inner a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
outer = String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
str String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
                            | Bool
otherwise = String
str

-- | Check whether a term has any hole bindings in it - impure if so
pureTerm :: TT Name -> Bool
pureTerm :: TT Name -> Bool
pureTerm (App AppStatus Name
_ TT Name
f TT Name
a) = TT Name -> Bool
pureTerm TT Name
f Bool -> Bool -> Bool
&& TT Name -> Bool
pureTerm TT Name
a
pureTerm (Bind Name
n Binder (TT Name)
b TT Name
sc) = Name -> Bool
notInterfaceName Name
n Bool -> Bool -> Bool
&& Binder (TT Name) -> Bool
pureBinder Binder (TT Name)
b Bool -> Bool -> Bool
&& TT Name -> Bool
pureTerm TT Name
sc where
    pureBinder :: Binder (TT Name) -> Bool
pureBinder (Hole TT Name
_) = Bool
False
    pureBinder (Guess TT Name
_ TT Name
_) = Bool
False
    pureBinder (Let RigCount
c TT Name
t TT Name
v) = TT Name -> Bool
pureTerm TT Name
t Bool -> Bool -> Bool
&& TT Name -> Bool
pureTerm TT Name
v
    pureBinder Binder (TT Name)
t = TT Name -> Bool
pureTerm (Binder (TT Name) -> TT Name
forall b. Binder b -> b
binderTy Binder (TT Name)
t)

    notInterfaceName :: Name -> Bool
notInterfaceName (MN Int
_ Text
c) | Text
c Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
txt String
"__interface" = Bool
False
    notInterfaceName Name
_ = Bool
True

pureTerm TT Name
_ = Bool
True

-- | Weaken a term by adding i to each de Bruijn index (i.e. lift it over i bindings)
weakenTm :: Int -> TT n -> TT n
weakenTm :: forall {n}. Int -> TT n -> TT n
weakenTm Int
i TT n
t = Int -> Int -> TT n -> TT n
forall {n}. Int -> Int -> TT n -> TT n
wk Int
i Int
0 TT n
t
  where wk :: Int -> Int -> TT n -> TT n
wk Int
i Int
min (V Int
x) | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
min = Int -> TT n
forall n. Int -> TT n
V (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x)
        wk Int
i Int
m (App AppStatus n
s TT n
f TT n
a)   = AppStatus n -> TT n -> TT n -> TT n
forall n. AppStatus n -> TT n -> TT n -> TT n
App AppStatus n
s (Int -> Int -> TT n -> TT n
wk Int
i Int
m TT n
f) (Int -> Int -> TT n -> TT n
wk Int
i Int
m TT n
a)
        wk Int
i Int
m (Bind n
x Binder (TT n)
b TT n
sc) = n -> Binder (TT n) -> TT n -> TT n
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind n
x (Int -> Int -> Binder (TT n) -> Binder (TT n)
wkb Int
i Int
m Binder (TT n)
b) (Int -> Int -> TT n -> TT n
wk Int
i (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) TT n
sc)
        wk Int
i Int
m TT n
t = TT n
t
        wkb :: Int -> Int -> Binder (TT n) -> Binder (TT n)
wkb Int
i Int
m Binder (TT n)
t           = (TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Int -> TT n -> TT n
wk Int
i Int
m) Binder (TT n)
t

-- | Weaken an environment so that all the de Bruijn indices are correct according
-- to the latest bound variable

weakenEnv :: EnvTT n -> EnvTT n
weakenEnv :: forall n. EnvTT n -> EnvTT n
weakenEnv EnvTT n
env = Int -> EnvTT n -> EnvTT n
forall {a} {b} {n}.
Int -> [(a, b, Binder (TT n))] -> [(a, b, Binder (TT n))]
wk (EnvTT n -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length EnvTT n
env Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) EnvTT n
env
  where wk :: Int -> [(a, b, Binder (TT n))] -> [(a, b, Binder (TT n))]
wk Int
i [] = []
        wk Int
i ((a
n, b
c, Binder (TT n)
b) : [(a, b, Binder (TT n))]
bs) = (a
n, b
c, Int -> Binder (TT n) -> Binder (TT n)
forall {n}. Int -> Binder (TT n) -> Binder (TT n)
weakenTmB Int
i Binder (TT n)
b) (a, b, Binder (TT n))
-> [(a, b, Binder (TT n))] -> [(a, b, Binder (TT n))]
forall a. a -> [a] -> [a]
: Int -> [(a, b, Binder (TT n))] -> [(a, b, Binder (TT n))]
wk (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [(a, b, Binder (TT n))]
bs
        weakenTmB :: Int -> Binder (TT n) -> Binder (TT n)
weakenTmB Int
i (Let RigCount
c TT n
t TT n
v) = RigCount -> TT n -> TT n -> Binder (TT n)
forall b. RigCount -> b -> b -> Binder b
Let RigCount
c (Int -> TT n -> TT n
forall {n}. Int -> TT n -> TT n
weakenTm Int
i TT n
t) (Int -> TT n -> TT n
forall {n}. Int -> TT n -> TT n
weakenTm Int
i TT n
v)
        weakenTmB Int
i (Guess TT n
t TT n
v) = TT n -> TT n -> Binder (TT n)
forall b. b -> b -> Binder b
Guess (Int -> TT n -> TT n
forall {n}. Int -> TT n -> TT n
weakenTm Int
i TT n
t) (Int -> TT n -> TT n
forall {n}. Int -> TT n -> TT n
weakenTm Int
i TT n
v)
        weakenTmB Int
i Binder (TT n)
t           = Binder (TT n)
t { binderTy = weakenTm i (binderTy t) }

-- | Weaken every term in the environment by the given amount
weakenTmEnv :: Int -> EnvTT n -> EnvTT n
weakenTmEnv :: forall n. Int -> EnvTT n -> EnvTT n
weakenTmEnv Int
i = ((n, RigCount, Binder (TT n)) -> (n, RigCount, Binder (TT n)))
-> [(n, RigCount, Binder (TT n))] -> [(n, RigCount, Binder (TT n))]
forall a b. (a -> b) -> [a] -> [b]
map (\ (n
n, RigCount
c, Binder (TT n)
b) -> (n
n, RigCount
c, (TT n -> TT n) -> Binder (TT n) -> Binder (TT n)
forall a b. (a -> b) -> Binder a -> Binder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> TT n -> TT n
forall {n}. Int -> TT n -> TT n
weakenTm Int
i) Binder (TT n)
b))

refsIn :: TT Name -> [Name]
refsIn :: TT Name -> [Name]
refsIn (P NameType
_ Name
n TT Name
_) = [Name
n]
refsIn (Bind Name
n Binder (TT Name)
b TT Name
t) = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub ([Name] -> [Name]) -> [Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ Binder (TT Name) -> [Name]
nb Binder (TT Name)
b [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ TT Name -> [Name]
refsIn TT Name
t
  where nb :: Binder (TT Name) -> [Name]
nb (Let RigCount
_ TT Name
t TT Name
v) = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub (TT Name -> [Name]
refsIn TT Name
t) [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub (TT Name -> [Name]
refsIn TT Name
v)
        nb (Guess TT Name
t TT Name
v) = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub (TT Name -> [Name]
refsIn TT Name
t) [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub (TT Name -> [Name]
refsIn TT Name
v)
        nb Binder (TT Name)
t = TT Name -> [Name]
refsIn (Binder (TT Name) -> TT Name
forall b. Binder b -> b
binderTy Binder (TT Name)
t)
refsIn (App AppStatus Name
s TT Name
f TT Name
a) = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub (TT Name -> [Name]
refsIn TT Name
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ TT Name -> [Name]
refsIn TT Name
a)
refsIn TT Name
_ = []

allTTNames :: Eq n => TT n -> [n]
allTTNames :: forall n. Eq n => TT n -> [n]
allTTNames = [n] -> [n]
forall a. Eq a => [a] -> [a]
nub ([n] -> [n]) -> (TT n -> [n]) -> TT n -> [n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TT n -> [n]
forall {a}. TT a -> [a]
allNamesIn
  where allNamesIn :: TT a -> [a]
allNamesIn (P NameType
_ a
n TT a
_) = [a
n]
        allNamesIn (Bind a
n Binder (TT a)
b TT a
t) = [a
n] [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ Binder (TT a) -> [a]
nb Binder (TT a)
b [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ TT a -> [a]
allNamesIn TT a
t
          where nb :: Binder (TT a) -> [a]
nb (Let RigCount
_ TT a
t TT a
v) = TT a -> [a]
allNamesIn TT a
t [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ TT a -> [a]
allNamesIn TT a
v
                nb (Guess TT a
t TT a
v) = TT a -> [a]
allNamesIn TT a
t [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ TT a -> [a]
allNamesIn TT a
v
                nb Binder (TT a)
t = TT a -> [a]
allNamesIn (Binder (TT a) -> TT a
forall b. Binder b -> b
binderTy Binder (TT a)
t)
        allNamesIn (App AppStatus a
_ TT a
f TT a
a) = TT a -> [a]
allNamesIn TT a
f [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ TT a -> [a]
allNamesIn TT a
a
        allNamesIn TT a
_ = []


-- | Pretty-print a term
pprintTT :: [Name]  -- ^ The bound names (for highlighting and de Bruijn indices)
         -> TT Name -- ^ The term to be printed
         -> Doc OutputAnnotation
pprintTT :: [Name] -> TT Name -> Doc OutputAnnotation
pprintTT [Name]
bound TT Name
tm = Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
tm

  where
    startPrec :: Integer
startPrec = Integer
0
    appPrec :: Integer
appPrec   = Integer
10

    pp :: Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
p [Name]
bound (P NameType
Bound Name
n TT Name
ty) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
False) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation) -> String -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Show a => a -> String
show Name
n)
    pp Integer
p [Name]
bound (P NameType
nt Name
n TT Name
ty) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing)
                                          (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation) -> String -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Show a => a -> String
show Name
n)
    pp Integer
p [Name]
bound (V Int
i)
       | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< [Name] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Name]
bound = let n :: Name
n = [Name]
bound [Name] -> Int -> Name
forall a. HasCallStack => [a] -> Int -> a
!! Int
i
                            in OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
False) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation) -> String -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Show a => a -> String
show Name
n)
       | Bool
otherwise        = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String
"{{{V" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"}}}")
    pp Integer
p [Name]
bound (Bind Name
n Binder (TT Name)
b TT Name
sc) = Integer
-> [Name]
-> Name
-> Binder (TT Name)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
ppb Integer
p [Name]
bound Name
n Binder (TT Name)
b (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                               Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
bound) TT Name
sc
    pp Integer
p [Name]
bound (App AppStatus Name
_ TT Name
tm1 TT Name
tm2) =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
appPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
        Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
appPrec [Name]
bound TT Name
tm1 Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
        Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp (Integer
appPrec Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
1) [Name]
bound TT Name
tm2
    pp Integer
p [Name]
bound (Constant Const
c) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Const -> OutputAnnotation
AnnConst Const
c) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Const -> String
forall a. Show a => a -> String
show Const
c))
    pp Integer
p [Name]
bound (Proj TT Name
tm Int
i) =
      Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
tm Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
rparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"!" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Int -> String
forall a. Show a => a -> String
show Int
i)
    pp Integer
p [Name]
bound TT Name
Erased = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"<<<erased>>>"
    pp Integer
p [Name]
bound TT Name
Impossible = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"<<<impossible>>>"
    pp Integer
p [Name]
bound (Inferred TT Name
t) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"<" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
p [Name]
bound TT Name
t Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
">"
    pp Integer
p [Name]
bound (TType UExp
ue) = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnType String
"Type" String
"The type of types") (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                            String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Type"
    pp Integer
p [Name]
bound (UType Universe
u) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Universe -> String
forall a. Show a => a -> String
show Universe
u)

    ppb :: Integer
-> [Name]
-> Name
-> Binder (TT Name)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
ppb Integer
p [Name]
bound Name
n (Lam RigCount
rig TT Name
ty) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"λ" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"." Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
sc
    ppb Integer
p [Name]
bound Name
n (Pi RigCount
rig Maybe ImplicitInfo
_ TT Name
ty TT Name
k) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> (Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align) (Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
ty) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      Doc OutputAnnotation
forall a. Doc a
rparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> RigCount -> Doc OutputAnnotation
forall {a}. RigCount -> Doc a
mkArrow RigCount
rig Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
sc
        where mkArrow :: RigCount -> Doc a
mkArrow RigCount
Rig1 = String -> Doc a
forall a. String -> Doc a
text String
"⇴"
              mkArrow RigCount
Rig0 = String -> Doc a
forall a. String -> Doc a
text String
"⥛"
              mkArrow RigCount
_ = String -> Doc a
forall a. String -> Doc a
text String
"→"
    ppb Integer
p [Name]
bound Name
n (Let RigCount
_ TT Name
ty TT Name
val) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2) (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"let") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                        Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                        Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                        String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
                        Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
val) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2) (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"in") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
sc)
    ppb Integer
p [Name]
bound Name
n (NLet TT Name
ty TT Name
val) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2) (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"nlet") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                        Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                        Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                        String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
                        Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
val) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2) (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"in") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
sc)
    ppb Integer
p [Name]
bound Name
n (Hole TT Name
ty) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"?" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"." Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
sc
    ppb Integer
p [Name]
bound Name
n (GHole Int
_ [Name]
_ TT Name
ty) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"¿" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"." Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
sc
    ppb Integer
p [Name]
bound Name
n (Guess TT Name
ty TT Name
val) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"?" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"≈" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
val Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"." Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
sc
    ppb Integer
p [Name]
bound Name
n (PVar RigCount
_ TT Name
ty) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"pat") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"." Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      Doc OutputAnnotation
sc
    ppb Integer
p [Name]
bound Name
n (PVTy TT Name
ty) Doc OutputAnnotation
sc =
      Integer -> Integer -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Integer
p Integer
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"patTy") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Integer -> [Name] -> TT Name -> Doc OutputAnnotation
pp Integer
startPrec [Name]
bound TT Name
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"." Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      Doc OutputAnnotation
sc

    bracket :: a -> a -> Doc a -> Doc a
bracket a
outer a
inner Doc a
doc
      | a
outer a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
inner = Doc a
forall a. Doc a
lparen Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> Doc a
doc Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> Doc a
forall a. Doc a
rparen
      | Bool
otherwise     = Doc a
doc

pprintTTClause :: [(Name, Type)] -> Term -> Term -> Doc OutputAnnotation
pprintTTClause :: [(Name, TT Name)] -> TT Name -> TT Name -> Doc OutputAnnotation
pprintTTClause [(Name, TT Name)]
pvars TT Name
lhs TT Name
rhs =
    [(Name, TT Name)] -> Doc OutputAnnotation -> Doc OutputAnnotation
vars [(Name, TT Name)]
pvars (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      [Name] -> TT Name -> Doc OutputAnnotation
pprintTT (((Name, TT Name) -> Name) -> [(Name, TT Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TT Name) -> Name
forall a b. (a, b) -> a
fst [(Name, TT Name)]
pvars) TT Name
lhs Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"↦" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
      ([Name] -> TT Name -> Doc OutputAnnotation
pprintTT (((Name, TT Name) -> Name) -> [(Name, TT Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TT Name) -> Name
forall a b. (a, b) -> a
fst [(Name, TT Name)]
pvars) TT Name
rhs)
  where vars :: [(Name, TT Name)] -> Doc OutputAnnotation -> Doc OutputAnnotation
vars [] Doc OutputAnnotation
terms = Doc OutputAnnotation
terms
        vars ((Name, TT Name)
v:[(Name, TT Name)]
vs) Doc OutputAnnotation
terms =
          OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"var") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
sep (Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. Doc a -> [Doc a] -> [Doc a]
punctuate Doc OutputAnnotation
forall a. Doc a
comma ([Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. [a] -> [a]
reverse ([Name] -> [(Name, TT Name)] -> [Doc OutputAnnotation]
bindVars [] ((Name, TT Name)
v(Name, TT Name) -> [(Name, TT Name)] -> [(Name, TT Name)]
forall a. a -> [a] -> [a]
:[(Name, TT Name)]
vs)))))) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
          OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
".") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
          Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
indent Int
2 Doc OutputAnnotation
terms
        bindVars :: [Name] -> [(Name, TT Name)] -> [Doc OutputAnnotation]
bindVars [Name]
_ [] = []
        bindVars [Name]
ns ((Name
n, TT Name
ty):[(Name, TT Name)]
vs) =
          Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> [Name] -> TT Name -> Doc OutputAnnotation
pprintTT [Name]
ns TT Name
ty Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
: [Name] -> [(Name, TT Name)] -> [Doc OutputAnnotation]
bindVars (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
ns) [(Name, TT Name)]
vs


-- | Pretty-print a raw term.
pprintRaw :: [Name] -- ^ Bound names, for highlighting
          -> Raw -- ^ The term to pretty-print
          -> Doc OutputAnnotation
pprintRaw :: [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound (Var Name
n) =
  Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
    (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Var") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (if Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
bound
                                  then Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
False
                                  else Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing)
                              (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation) -> String -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Show a => a -> String
show Name
n)
pprintRaw [Name]
bound (RBind Name
n Binder Raw
b Raw
body) =
  Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
  [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep [ String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"RBind"
       , OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
False) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (String -> Doc OutputAnnotation) -> String -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Show a => a -> String
show Name
n)
       , Binder Raw -> Doc OutputAnnotation
ppb Binder Raw
b
       , [Name] -> Raw -> Doc OutputAnnotation
pprintRaw (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
bound) Raw
body]
  where
    ppb :: Binder Raw -> Doc OutputAnnotation
ppb (Lam RigCount
_ Raw
ty) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                     String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Lam" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty
    ppb (Pi RigCount
_ Maybe ImplicitInfo
_ Raw
ty Raw
k) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                        [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep [String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Pi", [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty, [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
k]
    ppb (Let RigCount
c Raw
ty Raw
v) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                       [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep [String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Let", [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty, [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
v]
    ppb (NLet Raw
ty Raw
v) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                      [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep [String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"NLet", [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty, [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
v]
    ppb (Hole Raw
ty) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                    String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Hole" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty
    ppb (GHole Int
_ [Name]
_ Raw
ty) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                         String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"GHole" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty
    ppb (Guess Raw
ty Raw
v) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                       [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep [String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Guess", [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty, [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
v]
    ppb (PVar RigCount
_ Raw
ty) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"PVar" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty
    ppb (PVTy Raw
ty) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                    String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"PVTy" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
ty
pprintRaw [Name]
bound (RApp Raw
f Raw
x) =
  Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
  [String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"RApp", [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
f, [Name] -> Raw -> Doc OutputAnnotation
pprintRaw [Name]
bound Raw
x]
pprintRaw [Name]
bound Raw
RType = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"RType"
pprintRaw [Name]
bound (RUType Universe
u) = Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                             String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"RUType" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Universe -> String
forall a. Show a => a -> String
show Universe
u)
pprintRaw [Name]
bound (RConstant Const
c) =
  Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
  [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep [String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"RConstant", OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Const -> OutputAnnotation
AnnConst Const
c) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Const -> String
forall a. Show a => a -> String
show Const
c))]

-- | Pretty-printer helper for the binding site of a name
bindingOf :: Name -- ^^ the bound name
          -> Bool -- ^^ whether the name is implicit
          -> Doc OutputAnnotation
bindingOf :: Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
imp = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
imp) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
forall a. Show a => a -> String
show Name
n))