module U.Codebase.Term where

import Control.Lens hiding (List)
import Control.Monad.State
import Control.Monad.Writer qualified as Writer
import Data.Foldable qualified as Foldable
import Data.Map qualified as Map
import Data.Set qualified as Set
import U.Codebase.Reference (Reference, Reference')
import U.Codebase.Reference qualified as Reference
import U.Codebase.Referent (Referent')
import U.Codebase.Referent qualified as Referent
import U.Codebase.Type (TypeR)
import U.Codebase.Type qualified as Type
import U.Core.ABT qualified as ABT
import U.Core.ABT.Var qualified as ABT
import Unison.Hash (Hash)
import Unison.Prelude
import Unison.Util.Recursion

type ConstructorId = Word64

type Term v = ABT.Term (F v) v ()

-- | A version of 'Term' but where TermRefs never have a 'Nothing' Hash, but instead self references
-- are filled with User Variable references
-- to the relevant piece of the component in a component map.
type HashableTerm v = ABT.Term (F' Text HashableTermRef TypeRef HashableTermLink TypeLink v) v ()

type Type v = TypeR TypeRef v

type TermRef = Reference' Text (Maybe Hash)

type HashableTermRef = Reference' Text Hash

type TypeRef = Reference

type TermLink = Referent' (Reference' Text (Maybe Hash)) (Reference' Text Hash)

type HashableTermLink = Referent' (Reference' Text Hash) (Reference' Text Hash)

type TypeLink = Reference

-- | Base functor for terms in the Unison codebase
type F vt =
  F'
    Text
    TermRef
    TypeRef
    TermLink
    TypeLink
    vt

-- | Generalized version.  We could generalize further to allow sharing within
--  terms.
data F' text termRef typeRef termLink typeLink vt a
  = Int Int64
  | Nat Word64
  | Float Double
  | Boolean Bool
  | Text text
  | Char Char
  | Ref termRef
  | -- First argument identifies the data type,
    -- second argument identifies the constructor
    Constructor typeRef ConstructorId
  | Request typeRef ConstructorId
  | Handle a a
  | App a a
  | Ann a (TypeR typeRef vt)
  | List (Seq a)
  | If a a a
  | And a a
  | Or a a
  | Lam a
  | -- Note: let rec blocks have an outer ABT.Cycle which introduces as many
    -- variables as there are bindings
    LetRec [a] a
  | -- Note: first parameter is the binding, second is the expression which may refer
    -- to this let bound variable. Constructed as `Let b (abs v e)`
    Let a a
  | -- Pattern matching / eliminating data types, example:
    --  case x of
    --    Just n -> rhs1
    --    Nothing -> rhs2
    --
    -- translates to
    --
    --   Match x
    --     [ (Constructor 0 [Var], ABT.abs n rhs1)
    --     , (Constructor 1 [], rhs2) ]
    Match a [MatchCase text typeRef a]
  | TermLink termLink
  | TypeLink typeLink
  deriving ((forall m.
 Monoid m =>
 F' text termRef typeRef termLink typeLink vt m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m)
-> (forall a b.
    (a -> b -> b)
    -> b -> F' text termRef typeRef termLink typeLink vt a -> b)
-> (forall a b.
    (a -> b -> b)
    -> b -> F' text termRef typeRef termLink typeLink vt a -> b)
-> (forall b a.
    (b -> a -> b)
    -> b -> F' text termRef typeRef termLink typeLink vt a -> b)
-> (forall b a.
    (b -> a -> b)
    -> b -> F' text termRef typeRef termLink typeLink vt a -> b)
-> (forall a.
    (a -> a -> a)
    -> F' text termRef typeRef termLink typeLink vt a -> a)
-> (forall a.
    (a -> a -> a)
    -> F' text termRef typeRef termLink typeLink vt a -> a)
-> (forall a.
    F' text termRef typeRef termLink typeLink vt a -> [a])
-> (forall a.
    F' text termRef typeRef termLink typeLink vt a -> Bool)
-> (forall a.
    F' text termRef typeRef termLink typeLink vt a -> Int)
-> (forall a.
    Eq a =>
    a -> F' text termRef typeRef termLink typeLink vt a -> Bool)
-> (forall a.
    Ord a =>
    F' text termRef typeRef termLink typeLink vt a -> a)
-> (forall a.
    Ord a =>
    F' text termRef typeRef termLink typeLink vt a -> a)
-> (forall a.
    Num a =>
    F' text termRef typeRef termLink typeLink vt a -> a)
-> (forall a.
    Num a =>
    F' text termRef typeRef termLink typeLink vt a -> a)
-> Foldable (F' text termRef typeRef termLink typeLink vt)
forall a.
Eq a =>
a -> F' text termRef typeRef termLink typeLink vt a -> Bool
forall a.
Num a =>
F' text termRef typeRef termLink typeLink vt a -> a
forall a.
Ord a =>
F' text termRef typeRef termLink typeLink vt a -> a
forall m.
Monoid m =>
F' text termRef typeRef termLink typeLink vt m -> m
forall a. F' text termRef typeRef termLink typeLink vt a -> Bool
forall a. F' text termRef typeRef termLink typeLink vt a -> Int
forall a. F' text termRef typeRef termLink typeLink vt a -> [a]
forall a.
(a -> a -> a)
-> F' text termRef typeRef termLink typeLink vt a -> a
forall m a.
Monoid m =>
(a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m
forall b a.
(b -> a -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
forall a b.
(a -> b -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
forall text termRef typeRef termLink typeLink vt a.
Eq a =>
a -> F' text termRef typeRef termLink typeLink vt a -> Bool
forall text termRef typeRef termLink typeLink vt a.
Num a =>
F' text termRef typeRef termLink typeLink vt a -> a
forall text termRef typeRef termLink typeLink vt a.
Ord a =>
F' text termRef typeRef termLink typeLink vt a -> a
forall text termRef typeRef termLink typeLink vt m.
Monoid m =>
F' text termRef typeRef termLink typeLink vt m -> m
forall text termRef typeRef termLink typeLink vt a.
F' text termRef typeRef termLink typeLink vt a -> Bool
forall text termRef typeRef termLink typeLink vt a.
F' text termRef typeRef termLink typeLink vt a -> Int
forall text termRef typeRef termLink typeLink vt a.
F' text termRef typeRef termLink typeLink vt a -> [a]
forall text termRef typeRef termLink typeLink vt a.
(a -> a -> a)
-> F' text termRef typeRef termLink typeLink vt a -> a
forall text termRef typeRef termLink typeLink vt m a.
Monoid m =>
(a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m
forall text termRef typeRef termLink typeLink vt b a.
(b -> a -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
forall text termRef typeRef termLink typeLink vt a b.
(a -> b -> b)
-> b -> F' text termRef typeRef termLink typeLink vt 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 text termRef typeRef termLink typeLink vt m.
Monoid m =>
F' text termRef typeRef termLink typeLink vt m -> m
fold :: forall m.
Monoid m =>
F' text termRef typeRef termLink typeLink vt m -> m
$cfoldMap :: forall text termRef typeRef termLink typeLink vt m a.
Monoid m =>
(a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m
foldMap :: forall m a.
Monoid m =>
(a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m
$cfoldMap' :: forall text termRef typeRef termLink typeLink vt m a.
Monoid m =>
(a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m
foldMap' :: forall m a.
Monoid m =>
(a -> m) -> F' text termRef typeRef termLink typeLink vt a -> m
$cfoldr :: forall text termRef typeRef termLink typeLink vt a b.
(a -> b -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
foldr :: forall a b.
(a -> b -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
$cfoldr' :: forall text termRef typeRef termLink typeLink vt a b.
(a -> b -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
foldr' :: forall a b.
(a -> b -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
$cfoldl :: forall text termRef typeRef termLink typeLink vt b a.
(b -> a -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
foldl :: forall b a.
(b -> a -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
$cfoldl' :: forall text termRef typeRef termLink typeLink vt b a.
(b -> a -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
foldl' :: forall b a.
(b -> a -> b)
-> b -> F' text termRef typeRef termLink typeLink vt a -> b
$cfoldr1 :: forall text termRef typeRef termLink typeLink vt a.
(a -> a -> a)
-> F' text termRef typeRef termLink typeLink vt a -> a
foldr1 :: forall a.
(a -> a -> a)
-> F' text termRef typeRef termLink typeLink vt a -> a
$cfoldl1 :: forall text termRef typeRef termLink typeLink vt a.
(a -> a -> a)
-> F' text termRef typeRef termLink typeLink vt a -> a
foldl1 :: forall a.
(a -> a -> a)
-> F' text termRef typeRef termLink typeLink vt a -> a
$ctoList :: forall text termRef typeRef termLink typeLink vt a.
F' text termRef typeRef termLink typeLink vt a -> [a]
toList :: forall a. F' text termRef typeRef termLink typeLink vt a -> [a]
$cnull :: forall text termRef typeRef termLink typeLink vt a.
F' text termRef typeRef termLink typeLink vt a -> Bool
null :: forall a. F' text termRef typeRef termLink typeLink vt a -> Bool
$clength :: forall text termRef typeRef termLink typeLink vt a.
F' text termRef typeRef termLink typeLink vt a -> Int
length :: forall a. F' text termRef typeRef termLink typeLink vt a -> Int
$celem :: forall text termRef typeRef termLink typeLink vt a.
Eq a =>
a -> F' text termRef typeRef termLink typeLink vt a -> Bool
elem :: forall a.
Eq a =>
a -> F' text termRef typeRef termLink typeLink vt a -> Bool
$cmaximum :: forall text termRef typeRef termLink typeLink vt a.
Ord a =>
F' text termRef typeRef termLink typeLink vt a -> a
maximum :: forall a.
Ord a =>
F' text termRef typeRef termLink typeLink vt a -> a
$cminimum :: forall text termRef typeRef termLink typeLink vt a.
Ord a =>
F' text termRef typeRef termLink typeLink vt a -> a
minimum :: forall a.
Ord a =>
F' text termRef typeRef termLink typeLink vt a -> a
$csum :: forall text termRef typeRef termLink typeLink vt a.
Num a =>
F' text termRef typeRef termLink typeLink vt a -> a
sum :: forall a.
Num a =>
F' text termRef typeRef termLink typeLink vt a -> a
$cproduct :: forall text termRef typeRef termLink typeLink vt a.
Num a =>
F' text termRef typeRef termLink typeLink vt a -> a
product :: forall a.
Num a =>
F' text termRef typeRef termLink typeLink vt a -> a
Foldable, (forall a b.
 (a -> b)
 -> F' text termRef typeRef termLink typeLink vt a
 -> F' text termRef typeRef termLink typeLink vt b)
-> (forall a b.
    a
    -> F' text termRef typeRef termLink typeLink vt b
    -> F' text termRef typeRef termLink typeLink vt a)
-> Functor (F' text termRef typeRef termLink typeLink vt)
forall a b.
a
-> F' text termRef typeRef termLink typeLink vt b
-> F' text termRef typeRef termLink typeLink vt a
forall a b.
(a -> b)
-> F' text termRef typeRef termLink typeLink vt a
-> F' text termRef typeRef termLink typeLink vt b
forall text termRef typeRef termLink typeLink vt a b.
a
-> F' text termRef typeRef termLink typeLink vt b
-> F' text termRef typeRef termLink typeLink vt a
forall text termRef typeRef termLink typeLink vt a b.
(a -> b)
-> F' text termRef typeRef termLink typeLink vt a
-> F' text termRef typeRef termLink typeLink vt b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall text termRef typeRef termLink typeLink vt a b.
(a -> b)
-> F' text termRef typeRef termLink typeLink vt a
-> F' text termRef typeRef termLink typeLink vt b
fmap :: forall a b.
(a -> b)
-> F' text termRef typeRef termLink typeLink vt a
-> F' text termRef typeRef termLink typeLink vt b
$c<$ :: forall text termRef typeRef termLink typeLink vt a b.
a
-> F' text termRef typeRef termLink typeLink vt b
-> F' text termRef typeRef termLink typeLink vt a
<$ :: forall a b.
a
-> F' text termRef typeRef termLink typeLink vt b
-> F' text termRef typeRef termLink typeLink vt a
Functor, Functor (F' text termRef typeRef termLink typeLink vt)
Foldable (F' text termRef typeRef termLink typeLink vt)
(Functor (F' text termRef typeRef termLink typeLink vt),
 Foldable (F' text termRef typeRef termLink typeLink vt)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b)
 -> F' text termRef typeRef termLink typeLink vt a
 -> f (F' text termRef typeRef termLink typeLink vt b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    F' text termRef typeRef termLink typeLink vt (f a)
    -> f (F' text termRef typeRef termLink typeLink vt a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> F' text termRef typeRef termLink typeLink vt a
    -> m (F' text termRef typeRef termLink typeLink vt b))
-> (forall (m :: * -> *) a.
    Monad m =>
    F' text termRef typeRef termLink typeLink vt (m a)
    -> m (F' text termRef typeRef termLink typeLink vt a))
-> Traversable (F' text termRef typeRef termLink typeLink vt)
forall text termRef typeRef termLink typeLink vt.
Functor (F' text termRef typeRef termLink typeLink vt)
forall text termRef typeRef termLink typeLink vt.
Foldable (F' text termRef typeRef termLink typeLink vt)
forall text termRef typeRef termLink typeLink vt (m :: * -> *) a.
Monad m =>
F' text termRef typeRef termLink typeLink vt (m a)
-> m (F' text termRef typeRef termLink typeLink vt a)
forall text termRef typeRef termLink typeLink vt (f :: * -> *) a.
Applicative f =>
F' text termRef typeRef termLink typeLink vt (f a)
-> f (F' text termRef typeRef termLink typeLink vt a)
forall text termRef typeRef termLink typeLink vt (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> F' text termRef typeRef termLink typeLink vt a
-> m (F' text termRef typeRef termLink typeLink vt b)
forall text termRef typeRef termLink typeLink vt (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> F' text termRef typeRef termLink typeLink vt a
-> f (F' text termRef typeRef termLink typeLink vt b)
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 =>
F' text termRef typeRef termLink typeLink vt (m a)
-> m (F' text termRef typeRef termLink typeLink vt a)
forall (f :: * -> *) a.
Applicative f =>
F' text termRef typeRef termLink typeLink vt (f a)
-> f (F' text termRef typeRef termLink typeLink vt a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> F' text termRef typeRef termLink typeLink vt a
-> m (F' text termRef typeRef termLink typeLink vt b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> F' text termRef typeRef termLink typeLink vt a
-> f (F' text termRef typeRef termLink typeLink vt b)
$ctraverse :: forall text termRef typeRef termLink typeLink vt (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> F' text termRef typeRef termLink typeLink vt a
-> f (F' text termRef typeRef termLink typeLink vt b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> F' text termRef typeRef termLink typeLink vt a
-> f (F' text termRef typeRef termLink typeLink vt b)
$csequenceA :: forall text termRef typeRef termLink typeLink vt (f :: * -> *) a.
Applicative f =>
F' text termRef typeRef termLink typeLink vt (f a)
-> f (F' text termRef typeRef termLink typeLink vt a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
F' text termRef typeRef termLink typeLink vt (f a)
-> f (F' text termRef typeRef termLink typeLink vt a)
$cmapM :: forall text termRef typeRef termLink typeLink vt (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> F' text termRef typeRef termLink typeLink vt a
-> m (F' text termRef typeRef termLink typeLink vt b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> F' text termRef typeRef termLink typeLink vt a
-> m (F' text termRef typeRef termLink typeLink vt b)
$csequence :: forall text termRef typeRef termLink typeLink vt (m :: * -> *) a.
Monad m =>
F' text termRef typeRef termLink typeLink vt (m a)
-> m (F' text termRef typeRef termLink typeLink vt a)
sequence :: forall (m :: * -> *) a.
Monad m =>
F' text termRef typeRef termLink typeLink vt (m a)
-> m (F' text termRef typeRef termLink typeLink vt a)
Traversable, Int -> F' text termRef typeRef termLink typeLink vt a -> ShowS
[F' text termRef typeRef termLink typeLink vt a] -> ShowS
F' text termRef typeRef termLink typeLink vt a -> String
(Int -> F' text termRef typeRef termLink typeLink vt a -> ShowS)
-> (F' text termRef typeRef termLink typeLink vt a -> String)
-> ([F' text termRef typeRef termLink typeLink vt a] -> ShowS)
-> Show (F' text termRef typeRef termLink typeLink vt a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text termRef typeRef termLink typeLink vt a.
(Show text, Show termRef, Show vt, Show a, Show termLink,
 Show typeLink, Show typeRef) =>
Int -> F' text termRef typeRef termLink typeLink vt a -> ShowS
forall text termRef typeRef termLink typeLink vt a.
(Show text, Show termRef, Show vt, Show a, Show termLink,
 Show typeLink, Show typeRef) =>
[F' text termRef typeRef termLink typeLink vt a] -> ShowS
forall text termRef typeRef termLink typeLink vt a.
(Show text, Show termRef, Show vt, Show a, Show termLink,
 Show typeLink, Show typeRef) =>
F' text termRef typeRef termLink typeLink vt a -> String
$cshowsPrec :: forall text termRef typeRef termLink typeLink vt a.
(Show text, Show termRef, Show vt, Show a, Show termLink,
 Show typeLink, Show typeRef) =>
Int -> F' text termRef typeRef termLink typeLink vt a -> ShowS
showsPrec :: Int -> F' text termRef typeRef termLink typeLink vt a -> ShowS
$cshow :: forall text termRef typeRef termLink typeLink vt a.
(Show text, Show termRef, Show vt, Show a, Show termLink,
 Show typeLink, Show typeRef) =>
F' text termRef typeRef termLink typeLink vt a -> String
show :: F' text termRef typeRef termLink typeLink vt a -> String
$cshowList :: forall text termRef typeRef termLink typeLink vt a.
(Show text, Show termRef, Show vt, Show a, Show termLink,
 Show typeLink, Show typeRef) =>
[F' text termRef typeRef termLink typeLink vt a] -> ShowS
showList :: [F' text termRef typeRef termLink typeLink vt a] -> ShowS
Show)

data MatchCase t r a = MatchCase (Pattern t r) (Maybe a) a
  deriving ((forall m. Monoid m => MatchCase t r m -> m)
-> (forall m a. Monoid m => (a -> m) -> MatchCase t r a -> m)
-> (forall m a. Monoid m => (a -> m) -> MatchCase t r a -> m)
-> (forall a b. (a -> b -> b) -> b -> MatchCase t r a -> b)
-> (forall a b. (a -> b -> b) -> b -> MatchCase t r a -> b)
-> (forall b a. (b -> a -> b) -> b -> MatchCase t r a -> b)
-> (forall b a. (b -> a -> b) -> b -> MatchCase t r a -> b)
-> (forall a. (a -> a -> a) -> MatchCase t r a -> a)
-> (forall a. (a -> a -> a) -> MatchCase t r a -> a)
-> (forall a. MatchCase t r a -> [a])
-> (forall a. MatchCase t r a -> Bool)
-> (forall a. MatchCase t r a -> Int)
-> (forall a. Eq a => a -> MatchCase t r a -> Bool)
-> (forall a. Ord a => MatchCase t r a -> a)
-> (forall a. Ord a => MatchCase t r a -> a)
-> (forall a. Num a => MatchCase t r a -> a)
-> (forall a. Num a => MatchCase t r a -> a)
-> Foldable (MatchCase t r)
forall a. Eq a => a -> MatchCase t r a -> Bool
forall a. Num a => MatchCase t r a -> a
forall a. Ord a => MatchCase t r a -> a
forall m. Monoid m => MatchCase t r m -> m
forall a. MatchCase t r a -> Bool
forall a. MatchCase t r a -> Int
forall a. MatchCase t r a -> [a]
forall a. (a -> a -> a) -> MatchCase t r a -> a
forall m a. Monoid m => (a -> m) -> MatchCase t r a -> m
forall b a. (b -> a -> b) -> b -> MatchCase t r a -> b
forall a b. (a -> b -> b) -> b -> MatchCase t r a -> b
forall t r a. Eq a => a -> MatchCase t r a -> Bool
forall t r a. Num a => MatchCase t r a -> a
forall t r a. Ord a => MatchCase t r a -> a
forall t r m. Monoid m => MatchCase t r m -> m
forall t r a. MatchCase t r a -> Bool
forall t r a. MatchCase t r a -> Int
forall t r a. MatchCase t r a -> [a]
forall t r a. (a -> a -> a) -> MatchCase t r a -> a
forall t r m a. Monoid m => (a -> m) -> MatchCase t r a -> m
forall t r b a. (b -> a -> b) -> b -> MatchCase t r a -> b
forall t r a b. (a -> b -> b) -> b -> MatchCase t r 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 t r m. Monoid m => MatchCase t r m -> m
fold :: forall m. Monoid m => MatchCase t r m -> m
$cfoldMap :: forall t r m a. Monoid m => (a -> m) -> MatchCase t r a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> MatchCase t r a -> m
$cfoldMap' :: forall t r m a. Monoid m => (a -> m) -> MatchCase t r a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> MatchCase t r a -> m
$cfoldr :: forall t r a b. (a -> b -> b) -> b -> MatchCase t r a -> b
foldr :: forall a b. (a -> b -> b) -> b -> MatchCase t r a -> b
$cfoldr' :: forall t r a b. (a -> b -> b) -> b -> MatchCase t r a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> MatchCase t r a -> b
$cfoldl :: forall t r b a. (b -> a -> b) -> b -> MatchCase t r a -> b
foldl :: forall b a. (b -> a -> b) -> b -> MatchCase t r a -> b
$cfoldl' :: forall t r b a. (b -> a -> b) -> b -> MatchCase t r a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> MatchCase t r a -> b
$cfoldr1 :: forall t r a. (a -> a -> a) -> MatchCase t r a -> a
foldr1 :: forall a. (a -> a -> a) -> MatchCase t r a -> a
$cfoldl1 :: forall t r a. (a -> a -> a) -> MatchCase t r a -> a
foldl1 :: forall a. (a -> a -> a) -> MatchCase t r a -> a
$ctoList :: forall t r a. MatchCase t r a -> [a]
toList :: forall a. MatchCase t r a -> [a]
$cnull :: forall t r a. MatchCase t r a -> Bool
null :: forall a. MatchCase t r a -> Bool
$clength :: forall t r a. MatchCase t r a -> Int
length :: forall a. MatchCase t r a -> Int
$celem :: forall t r a. Eq a => a -> MatchCase t r a -> Bool
elem :: forall a. Eq a => a -> MatchCase t r a -> Bool
$cmaximum :: forall t r a. Ord a => MatchCase t r a -> a
maximum :: forall a. Ord a => MatchCase t r a -> a
$cminimum :: forall t r a. Ord a => MatchCase t r a -> a
minimum :: forall a. Ord a => MatchCase t r a -> a
$csum :: forall t r a. Num a => MatchCase t r a -> a
sum :: forall a. Num a => MatchCase t r a -> a
$cproduct :: forall t r a. Num a => MatchCase t r a -> a
product :: forall a. Num a => MatchCase t r a -> a
Foldable, (forall a b. (a -> b) -> MatchCase t r a -> MatchCase t r b)
-> (forall a b. a -> MatchCase t r b -> MatchCase t r a)
-> Functor (MatchCase t r)
forall a b. a -> MatchCase t r b -> MatchCase t r a
forall a b. (a -> b) -> MatchCase t r a -> MatchCase t r b
forall t r a b. a -> MatchCase t r b -> MatchCase t r a
forall t r a b. (a -> b) -> MatchCase t r a -> MatchCase t r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall t r a b. (a -> b) -> MatchCase t r a -> MatchCase t r b
fmap :: forall a b. (a -> b) -> MatchCase t r a -> MatchCase t r b
$c<$ :: forall t r a b. a -> MatchCase t r b -> MatchCase t r a
<$ :: forall a b. a -> MatchCase t r b -> MatchCase t r a
Functor, (forall x. MatchCase t r a -> Rep (MatchCase t r a) x)
-> (forall x. Rep (MatchCase t r a) x -> MatchCase t r a)
-> Generic (MatchCase t r a)
forall x. Rep (MatchCase t r a) x -> MatchCase t r a
forall x. MatchCase t r a -> Rep (MatchCase t r a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t r a x. Rep (MatchCase t r a) x -> MatchCase t r a
forall t r a x. MatchCase t r a -> Rep (MatchCase t r a) x
$cfrom :: forall t r a x. MatchCase t r a -> Rep (MatchCase t r a) x
from :: forall x. MatchCase t r a -> Rep (MatchCase t r a) x
$cto :: forall t r a x. Rep (MatchCase t r a) x -> MatchCase t r a
to :: forall x. Rep (MatchCase t r a) x -> MatchCase t r a
Generic, (forall a. MatchCase t r a -> Rep1 (MatchCase t r) a)
-> (forall a. Rep1 (MatchCase t r) a -> MatchCase t r a)
-> Generic1 (MatchCase t r)
forall a. Rep1 (MatchCase t r) a -> MatchCase t r a
forall a. MatchCase t r a -> Rep1 (MatchCase t r) a
forall t r a. Rep1 (MatchCase t r) a -> MatchCase t r a
forall t r a. MatchCase t r a -> Rep1 (MatchCase t r) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall t r a. MatchCase t r a -> Rep1 (MatchCase t r) a
from1 :: forall a. MatchCase t r a -> Rep1 (MatchCase t r) a
$cto1 :: forall t r a. Rep1 (MatchCase t r) a -> MatchCase t r a
to1 :: forall a. Rep1 (MatchCase t r) a -> MatchCase t r a
Generic1, Functor (MatchCase t r)
Foldable (MatchCase t r)
(Functor (MatchCase t r), Foldable (MatchCase t r)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> MatchCase t r a -> f (MatchCase t r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    MatchCase t r (f a) -> f (MatchCase t r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> MatchCase t r a -> m (MatchCase t r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    MatchCase t r (m a) -> m (MatchCase t r a))
-> Traversable (MatchCase t r)
forall t r. Functor (MatchCase t r)
forall t r. Foldable (MatchCase t r)
forall t r (m :: * -> *) a.
Monad m =>
MatchCase t r (m a) -> m (MatchCase t r a)
forall t r (f :: * -> *) a.
Applicative f =>
MatchCase t r (f a) -> f (MatchCase t r a)
forall t r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MatchCase t r a -> m (MatchCase t r b)
forall t r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MatchCase t r a -> f (MatchCase t r b)
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 =>
MatchCase t r (m a) -> m (MatchCase t r a)
forall (f :: * -> *) a.
Applicative f =>
MatchCase t r (f a) -> f (MatchCase t r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MatchCase t r a -> m (MatchCase t r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MatchCase t r a -> f (MatchCase t r b)
$ctraverse :: forall t r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MatchCase t r a -> f (MatchCase t r b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MatchCase t r a -> f (MatchCase t r b)
$csequenceA :: forall t r (f :: * -> *) a.
Applicative f =>
MatchCase t r (f a) -> f (MatchCase t r a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
MatchCase t r (f a) -> f (MatchCase t r a)
$cmapM :: forall t r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MatchCase t r a -> m (MatchCase t r b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MatchCase t r a -> m (MatchCase t r b)
$csequence :: forall t r (m :: * -> *) a.
Monad m =>
MatchCase t r (m a) -> m (MatchCase t r a)
sequence :: forall (m :: * -> *) a.
Monad m =>
MatchCase t r (m a) -> m (MatchCase t r a)
Traversable, Int -> MatchCase t r a -> ShowS
[MatchCase t r a] -> ShowS
MatchCase t r a -> String
(Int -> MatchCase t r a -> ShowS)
-> (MatchCase t r a -> String)
-> ([MatchCase t r a] -> ShowS)
-> Show (MatchCase t r a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall t r a.
(Show t, Show r, Show a) =>
Int -> MatchCase t r a -> ShowS
forall t r a.
(Show t, Show r, Show a) =>
[MatchCase t r a] -> ShowS
forall t r a. (Show t, Show r, Show a) => MatchCase t r a -> String
$cshowsPrec :: forall t r a.
(Show t, Show r, Show a) =>
Int -> MatchCase t r a -> ShowS
showsPrec :: Int -> MatchCase t r a -> ShowS
$cshow :: forall t r a. (Show t, Show r, Show a) => MatchCase t r a -> String
show :: MatchCase t r a -> String
$cshowList :: forall t r a.
(Show t, Show r, Show a) =>
[MatchCase t r a] -> ShowS
showList :: [MatchCase t r a] -> ShowS
Show)

data Pattern t r
  = PUnbound
  | PVar
  | PBoolean !Bool
  | PInt !Int64
  | PNat !Word64
  | PFloat !Double
  | PText !t
  | PChar !Char
  | PConstructor !r !ConstructorId [Pattern t r]
  | PAs (Pattern t r)
  | PEffectPure (Pattern t r)
  | PEffectBind !r !ConstructorId [Pattern t r] (Pattern t r)
  | PSequenceLiteral [Pattern t r]
  | PSequenceOp (Pattern t r) !SeqOp (Pattern t r)
  deriving ((forall x. Pattern t r -> Rep (Pattern t r) x)
-> (forall x. Rep (Pattern t r) x -> Pattern t r)
-> Generic (Pattern t r)
forall x. Rep (Pattern t r) x -> Pattern t r
forall x. Pattern t r -> Rep (Pattern t r) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t r x. Rep (Pattern t r) x -> Pattern t r
forall t r x. Pattern t r -> Rep (Pattern t r) x
$cfrom :: forall t r x. Pattern t r -> Rep (Pattern t r) x
from :: forall x. Pattern t r -> Rep (Pattern t r) x
$cto :: forall t r x. Rep (Pattern t r) x -> Pattern t r
to :: forall x. Rep (Pattern t r) x -> Pattern t r
Generic, (forall a b. (a -> b) -> Pattern t a -> Pattern t b)
-> (forall a b. a -> Pattern t b -> Pattern t a)
-> Functor (Pattern t)
forall a b. a -> Pattern t b -> Pattern t a
forall a b. (a -> b) -> Pattern t a -> Pattern t b
forall t a b. a -> Pattern t b -> Pattern t a
forall t a b. (a -> b) -> Pattern t a -> Pattern t b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall t a b. (a -> b) -> Pattern t a -> Pattern t b
fmap :: forall a b. (a -> b) -> Pattern t a -> Pattern t b
$c<$ :: forall t a b. a -> Pattern t b -> Pattern t a
<$ :: forall a b. a -> Pattern t b -> Pattern t a
Functor, (forall m. Monoid m => Pattern t m -> m)
-> (forall m a. Monoid m => (a -> m) -> Pattern t a -> m)
-> (forall m a. Monoid m => (a -> m) -> Pattern t a -> m)
-> (forall a b. (a -> b -> b) -> b -> Pattern t a -> b)
-> (forall a b. (a -> b -> b) -> b -> Pattern t a -> b)
-> (forall b a. (b -> a -> b) -> b -> Pattern t a -> b)
-> (forall b a. (b -> a -> b) -> b -> Pattern t a -> b)
-> (forall a. (a -> a -> a) -> Pattern t a -> a)
-> (forall a. (a -> a -> a) -> Pattern t a -> a)
-> (forall a. Pattern t a -> [a])
-> (forall a. Pattern t a -> Bool)
-> (forall a. Pattern t a -> Int)
-> (forall a. Eq a => a -> Pattern t a -> Bool)
-> (forall a. Ord a => Pattern t a -> a)
-> (forall a. Ord a => Pattern t a -> a)
-> (forall a. Num a => Pattern t a -> a)
-> (forall a. Num a => Pattern t a -> a)
-> Foldable (Pattern t)
forall a. Eq a => a -> Pattern t a -> Bool
forall a. Num a => Pattern t a -> a
forall a. Ord a => Pattern t a -> a
forall m. Monoid m => Pattern t m -> m
forall a. Pattern t a -> Bool
forall a. Pattern t a -> Int
forall a. Pattern t a -> [a]
forall a. (a -> a -> a) -> Pattern t a -> a
forall t a. Eq a => a -> Pattern t a -> Bool
forall t a. Num a => Pattern t a -> a
forall t a. Ord a => Pattern t a -> a
forall m a. Monoid m => (a -> m) -> Pattern t a -> m
forall t m. Monoid m => Pattern t m -> m
forall t a. Pattern t a -> Bool
forall t a. Pattern t a -> Int
forall t a. Pattern t a -> [a]
forall b a. (b -> a -> b) -> b -> Pattern t a -> b
forall a b. (a -> b -> b) -> b -> Pattern t a -> b
forall t a. (a -> a -> a) -> Pattern t a -> a
forall t m a. Monoid m => (a -> m) -> Pattern t a -> m
forall t b a. (b -> a -> b) -> b -> Pattern t a -> b
forall t a b. (a -> b -> b) -> b -> Pattern t 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 t m. Monoid m => Pattern t m -> m
fold :: forall m. Monoid m => Pattern t m -> m
$cfoldMap :: forall t m a. Monoid m => (a -> m) -> Pattern t a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Pattern t a -> m
$cfoldMap' :: forall t m a. Monoid m => (a -> m) -> Pattern t a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Pattern t a -> m
$cfoldr :: forall t a b. (a -> b -> b) -> b -> Pattern t a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Pattern t a -> b
$cfoldr' :: forall t a b. (a -> b -> b) -> b -> Pattern t a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Pattern t a -> b
$cfoldl :: forall t b a. (b -> a -> b) -> b -> Pattern t a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Pattern t a -> b
$cfoldl' :: forall t b a. (b -> a -> b) -> b -> Pattern t a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Pattern t a -> b
$cfoldr1 :: forall t a. (a -> a -> a) -> Pattern t a -> a
foldr1 :: forall a. (a -> a -> a) -> Pattern t a -> a
$cfoldl1 :: forall t a. (a -> a -> a) -> Pattern t a -> a
foldl1 :: forall a. (a -> a -> a) -> Pattern t a -> a
$ctoList :: forall t a. Pattern t a -> [a]
toList :: forall a. Pattern t a -> [a]
$cnull :: forall t a. Pattern t a -> Bool
null :: forall a. Pattern t a -> Bool
$clength :: forall t a. Pattern t a -> Int
length :: forall a. Pattern t a -> Int
$celem :: forall t a. Eq a => a -> Pattern t a -> Bool
elem :: forall a. Eq a => a -> Pattern t a -> Bool
$cmaximum :: forall t a. Ord a => Pattern t a -> a
maximum :: forall a. Ord a => Pattern t a -> a
$cminimum :: forall t a. Ord a => Pattern t a -> a
minimum :: forall a. Ord a => Pattern t a -> a
$csum :: forall t a. Num a => Pattern t a -> a
sum :: forall a. Num a => Pattern t a -> a
$cproduct :: forall t a. Num a => Pattern t a -> a
product :: forall a. Num a => Pattern t a -> a
Foldable, Functor (Pattern t)
Foldable (Pattern t)
(Functor (Pattern t), Foldable (Pattern t)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Pattern t a -> f (Pattern t b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Pattern t (f a) -> f (Pattern t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Pattern t a -> m (Pattern t b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Pattern t (m a) -> m (Pattern t a))
-> Traversable (Pattern t)
forall t. Functor (Pattern t)
forall t. Foldable (Pattern t)
forall t (m :: * -> *) a.
Monad m =>
Pattern t (m a) -> m (Pattern t a)
forall t (f :: * -> *) a.
Applicative f =>
Pattern t (f a) -> f (Pattern t a)
forall t (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Pattern t a -> m (Pattern t b)
forall t (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Pattern t a -> f (Pattern t b)
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 =>
Pattern t (m a) -> m (Pattern t a)
forall (f :: * -> *) a.
Applicative f =>
Pattern t (f a) -> f (Pattern t a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Pattern t a -> m (Pattern t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Pattern t a -> f (Pattern t b)
$ctraverse :: forall t (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Pattern t a -> f (Pattern t b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Pattern t a -> f (Pattern t b)
$csequenceA :: forall t (f :: * -> *) a.
Applicative f =>
Pattern t (f a) -> f (Pattern t a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Pattern t (f a) -> f (Pattern t a)
$cmapM :: forall t (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Pattern t a -> m (Pattern t b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Pattern t a -> m (Pattern t b)
$csequence :: forall t (m :: * -> *) a.
Monad m =>
Pattern t (m a) -> m (Pattern t a)
sequence :: forall (m :: * -> *) a.
Monad m =>
Pattern t (m a) -> m (Pattern t a)
Traversable, Int -> Pattern t r -> ShowS
[Pattern t r] -> ShowS
Pattern t r -> String
(Int -> Pattern t r -> ShowS)
-> (Pattern t r -> String)
-> ([Pattern t r] -> ShowS)
-> Show (Pattern t r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall t r. (Show t, Show r) => Int -> Pattern t r -> ShowS
forall t r. (Show t, Show r) => [Pattern t r] -> ShowS
forall t r. (Show t, Show r) => Pattern t r -> String
$cshowsPrec :: forall t r. (Show t, Show r) => Int -> Pattern t r -> ShowS
showsPrec :: Int -> Pattern t r -> ShowS
$cshow :: forall t r. (Show t, Show r) => Pattern t r -> String
show :: Pattern t r -> String
$cshowList :: forall t r. (Show t, Show r) => [Pattern t r] -> ShowS
showList :: [Pattern t r] -> ShowS
Show)

data SeqOp
  = PCons
  | PSnoc
  | PConcat
  deriving (SeqOp -> SeqOp -> Bool
(SeqOp -> SeqOp -> Bool) -> (SeqOp -> SeqOp -> Bool) -> Eq SeqOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SeqOp -> SeqOp -> Bool
== :: SeqOp -> SeqOp -> Bool
$c/= :: SeqOp -> SeqOp -> Bool
/= :: SeqOp -> SeqOp -> Bool
Eq, Int -> SeqOp -> ShowS
[SeqOp] -> ShowS
SeqOp -> String
(Int -> SeqOp -> ShowS)
-> (SeqOp -> String) -> ([SeqOp] -> ShowS) -> Show SeqOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SeqOp -> ShowS
showsPrec :: Int -> SeqOp -> ShowS
$cshow :: SeqOp -> String
show :: SeqOp -> String
$cshowList :: [SeqOp] -> ShowS
showList :: [SeqOp] -> ShowS
Show)

extraMap ::
  forall
    text
    termRef
    typeRef
    termLink
    typeLink
    vt
    text'
    termRef'
    typeRef'
    termLink'
    typeLink'
    vt'
    v
    a.
  (Ord v, Ord vt') =>
  (text -> text') ->
  (termRef -> termRef') ->
  (typeRef -> typeRef') ->
  (termLink -> termLink') ->
  (typeLink -> typeLink') ->
  (vt -> vt') ->
  ABT.Term (F' text termRef typeRef termLink typeLink vt) v a ->
  ABT.Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a
extraMap :: forall text termRef typeRef termLink typeLink vt text' termRef'
       typeRef' termLink' typeLink' vt' v a.
(Ord v, Ord vt') =>
(text -> text')
-> (termRef -> termRef')
-> (typeRef -> typeRef')
-> (termLink -> termLink')
-> (typeLink -> typeLink')
-> (vt -> vt')
-> Term (F' text termRef typeRef termLink typeLink vt) v a
-> Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a
extraMap text -> text'
ftext termRef -> termRef'
ftermRef typeRef -> typeRef'
ftypeRef termLink -> termLink'
ftermLink typeLink -> typeLink'
ftypeLink vt -> vt'
fvt Term (F' text termRef typeRef termLink typeLink vt) v a
t =
  Identity
  (Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
-> Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a
forall a. Identity a -> a
runIdentity (Identity
   (Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
 -> Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
-> Identity
     (Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
-> Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a
forall a b. (a -> b) -> a -> b
$ (text -> Identity text')
-> (termRef -> Identity termRef')
-> (typeRef -> Identity typeRef')
-> (termLink -> Identity termLink')
-> (typeLink -> Identity typeLink')
-> (vt -> Identity vt')
-> Term (F' text termRef typeRef termLink typeLink vt) v a
-> Identity
     (Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
forall (m :: * -> *) text termRef typeRef termLink typeLink vt
       text' termRef' typeRef' termLink' typeLink' vt' v a.
(Ord v, Ord vt', Monad m) =>
(text -> m text')
-> (termRef -> m termRef')
-> (typeRef -> m typeRef')
-> (termLink -> m termLink')
-> (typeLink -> m typeLink')
-> (vt -> m vt')
-> Term (F' text termRef typeRef termLink typeLink vt) v a
-> m (Term
        (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
extraMapM (text' -> Identity text'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (text' -> Identity text')
-> (text -> text') -> text -> Identity text'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. text -> text'
ftext) (termRef' -> Identity termRef'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (termRef' -> Identity termRef')
-> (termRef -> termRef') -> termRef -> Identity termRef'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. termRef -> termRef'
ftermRef) (typeRef' -> Identity typeRef'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (typeRef' -> Identity typeRef')
-> (typeRef -> typeRef') -> typeRef -> Identity typeRef'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. typeRef -> typeRef'
ftypeRef) (termLink' -> Identity termLink'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (termLink' -> Identity termLink')
-> (termLink -> termLink') -> termLink -> Identity termLink'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. termLink -> termLink'
ftermLink) (typeLink' -> Identity typeLink'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (typeLink' -> Identity typeLink')
-> (typeLink -> typeLink') -> typeLink -> Identity typeLink'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. typeLink -> typeLink'
ftypeLink) (vt' -> Identity vt'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (vt' -> Identity vt') -> (vt -> vt') -> vt -> Identity vt'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. vt -> vt'
fvt) Term (F' text termRef typeRef termLink typeLink vt) v a
t

extraMapM ::
  forall
    m
    text
    termRef
    typeRef
    termLink
    typeLink
    vt
    text'
    termRef'
    typeRef'
    termLink'
    typeLink'
    vt'
    v
    a.
  (Ord v, Ord vt', Monad m) =>
  (text -> m text') ->
  (termRef -> m termRef') ->
  (typeRef -> m typeRef') ->
  (termLink -> m termLink') ->
  (typeLink -> m typeLink') ->
  (vt -> m vt') ->
  ABT.Term (F' text termRef typeRef termLink typeLink vt) v a ->
  m (ABT.Term (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
extraMapM :: forall (m :: * -> *) text termRef typeRef termLink typeLink vt
       text' termRef' typeRef' termLink' typeLink' vt' v a.
(Ord v, Ord vt', Monad m) =>
(text -> m text')
-> (termRef -> m termRef')
-> (typeRef -> m typeRef')
-> (termLink -> m termLink')
-> (typeLink -> m typeLink')
-> (vt -> m vt')
-> Term (F' text termRef typeRef termLink typeLink vt) v a
-> m (Term
        (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
extraMapM text -> m text'
ftext termRef -> m termRef'
ftermRef typeRef -> m typeRef'
ftypeRef termLink -> m termLink'
ftermLink typeLink -> m typeLink'
ftypeLink vt -> m vt'
fvt = Term (F' text termRef typeRef termLink typeLink vt) v a
-> m (Term
        (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
go'
  where
    go' :: Term (F' text termRef typeRef termLink typeLink vt) v a
-> m (Term
        (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
go' = (forall a1.
 F' text termRef typeRef termLink typeLink vt a1
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' a1))
-> Term (F' text termRef typeRef termLink typeLink vt) v a
-> m (Term
        (F' text' termRef' typeRef' termLink' typeLink' vt') v a)
forall v (m :: * -> *) (g :: * -> *) (f :: * -> *) a.
(Ord v, Monad m, Traversable g) =>
(forall a1. f a1 -> m (g a1)) -> Term f v a -> m (Term g v a)
ABT.transformM F' text termRef typeRef termLink typeLink vt a1
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' a1)
forall a1.
F' text termRef typeRef termLink typeLink vt a1
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' a1)
go
    go :: forall x. F' text termRef typeRef termLink typeLink vt x -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
    go :: forall a1.
F' text termRef typeRef termLink typeLink vt a1
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' a1)
go = \case
      Int Int64
i -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ Int64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
Int64 -> F' text termRef typeRef termLink typeLink vt a
Int Int64
i
      Nat Word64
n -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ Word64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
Word64 -> F' text termRef typeRef termLink typeLink vt a
Nat Word64
n
      Float Double
d -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ Double -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
Double -> F' text termRef typeRef termLink typeLink vt a
Float Double
d
      Boolean Bool
b -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ Bool -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
Bool -> F' text termRef typeRef termLink typeLink vt a
Boolean Bool
b
      Text text
t -> text' -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
text -> F' text termRef typeRef termLink typeLink vt a
Text (text' -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m text'
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> text -> m text'
ftext text
t
      Char Char
c -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ Char -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
Char -> F' text termRef typeRef termLink typeLink vt a
Char Char
c
      Ref termRef
r -> termRef' -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
termRef -> F' text termRef typeRef termLink typeLink vt a
Ref (termRef' -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m termRef'
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> termRef -> m termRef'
ftermRef termRef
r
      Constructor typeRef
r Word64
cid -> typeRef'
-> Word64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
typeRef -> Word64 -> F' text termRef typeRef termLink typeLink vt a
Constructor (typeRef'
 -> Word64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m typeRef'
-> m (Word64
      -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (typeRef -> m typeRef'
ftypeRef typeRef
r) m (Word64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m Word64
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64 -> m Word64
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64
cid
      Request typeRef
r Word64
cid -> typeRef'
-> Word64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
typeRef -> Word64 -> F' text termRef typeRef termLink typeLink vt a
Request (typeRef'
 -> Word64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m typeRef'
-> m (Word64
      -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> typeRef -> m typeRef'
ftypeRef typeRef
r m (Word64 -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m Word64
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64 -> m Word64
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64
cid
      Handle x
e x
h -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ x -> x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
Handle x
e x
h
      App x
f x
a -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ x -> x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
App x
f x
a
      Ann x
a TypeR typeRef vt
typ -> x
-> TypeR typeRef' vt'
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a
-> TypeR typeRef vt
-> F' text termRef typeRef termLink typeLink vt a
Ann x
a (TypeR typeRef' vt'
 -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m (TypeR typeRef' vt')
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((vt -> m vt') -> TypeR typeRef vt -> m (Term (F' typeRef) vt' ())
forall (m :: * -> *) (f :: * -> *) v2 v a.
(Applicative m, Traversable f, Foldable f, Ord v2) =>
(v -> m v2) -> Term f v a -> m (Term f v2 a)
ABT.vmapM vt -> m vt'
fvt TypeR typeRef vt
typ m (Term (F' typeRef) vt' ())
-> (Term (F' typeRef) vt' () -> m (TypeR typeRef' vt'))
-> m (TypeR typeRef' vt')
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (typeRef -> m typeRef')
-> Term (F' typeRef) vt' () -> m (TypeR typeRef' vt')
forall v (f :: * -> *) r r' a.
(Ord v, Monad f) =>
(r -> f r') -> Term (F' r) v a -> f (Term (F' r') v a)
Type.rmapM typeRef -> m typeRef'
ftypeRef)
      List Seq x
s -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ Seq x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
Seq a -> F' text termRef typeRef termLink typeLink vt a
List Seq x
s
      If x
c x
t x
f -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ x -> x -> x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a -> a -> a -> F' text termRef typeRef termLink typeLink vt a
If x
c x
t x
f
      And x
p x
q -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ x -> x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
And x
p x
q
      Or x
p x
q -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ x -> x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
Or x
p x
q
      Lam x
b -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a -> F' text termRef typeRef termLink typeLink vt a
Lam x
b
      LetRec [x]
bs x
b -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ [x] -> x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
[a] -> a -> F' text termRef typeRef termLink typeLink vt a
LetRec [x]
bs x
b
      Let x
a x
b -> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (F' text' termRef' typeRef' termLink' typeLink' vt' x
 -> m (F' text' termRef' typeRef' termLink' typeLink' vt' x))
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall a b. (a -> b) -> a -> b
$ x -> x -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
Let x
a x
b
      Match x
s [MatchCase text typeRef x]
cs -> x
-> [MatchCase text' typeRef' x]
-> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
a
-> [MatchCase text typeRef a]
-> F' text termRef typeRef termLink typeLink vt a
Match x
s ([MatchCase text' typeRef' x]
 -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m [MatchCase text' typeRef' x]
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((MatchCase text typeRef x -> m (MatchCase text' typeRef' x))
-> [MatchCase text typeRef x] -> m [MatchCase text' typeRef' x]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse MatchCase text typeRef x -> m (MatchCase text' typeRef' x)
forall x.
MatchCase text typeRef x -> m (MatchCase text' typeRef' x)
goCase [MatchCase text typeRef x]
cs)
      TermLink termLink
r -> termLink' -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
termLink -> F' text termRef typeRef termLink typeLink vt a
TermLink (termLink' -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m termLink'
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> termLink -> m termLink'
ftermLink termLink
r
      TypeLink typeLink
r -> typeLink' -> F' text' termRef' typeRef' termLink' typeLink' vt' x
forall text termRef typeRef termLink typeLink vt a.
typeLink -> F' text termRef typeRef termLink typeLink vt a
TypeLink (typeLink' -> F' text' termRef' typeRef' termLink' typeLink' vt' x)
-> m typeLink'
-> m (F' text' termRef' typeRef' termLink' typeLink' vt' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> typeLink -> m typeLink'
ftypeLink typeLink
r
    goCase :: MatchCase text typeRef x -> m (MatchCase text' typeRef' x)
    goCase :: forall x.
MatchCase text typeRef x -> m (MatchCase text' typeRef' x)
goCase (MatchCase Pattern text typeRef
p Maybe x
g x
b) = Pattern text' typeRef'
-> Maybe x -> x -> MatchCase text' typeRef' x
forall t r a. Pattern t r -> Maybe a -> a -> MatchCase t r a
MatchCase (Pattern text' typeRef'
 -> Maybe x -> x -> MatchCase text' typeRef' x)
-> m (Pattern text' typeRef')
-> m (Maybe x -> x -> MatchCase text' typeRef' x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern text typeRef -> m (Pattern text' typeRef')
goPat Pattern text typeRef
p m (Maybe x -> x -> MatchCase text' typeRef' x)
-> m (Maybe x) -> m (x -> MatchCase text' typeRef' x)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe x -> m (Maybe x)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe x
g m (x -> MatchCase text' typeRef' x)
-> m x -> m (MatchCase text' typeRef' x)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> x -> m x
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure x
b
    goPat :: Pattern text typeRef -> m (Pattern text' typeRef')
goPat = (text -> m text')
-> (typeRef -> m typeRef')
-> Pattern text typeRef
-> m (Pattern text' typeRef')
forall (m :: * -> *) t t' r r'.
Applicative m =>
(t -> m t') -> (r -> m r') -> Pattern t r -> m (Pattern t' r')
rmapPatternM text -> m text'
ftext typeRef -> m typeRef'
ftypeRef

rmapPattern :: (t -> t') -> (r -> r') -> Pattern t r -> Pattern t' r'
rmapPattern :: forall t t' r r'.
(t -> t') -> (r -> r') -> Pattern t r -> Pattern t' r'
rmapPattern t -> t'
ft r -> r'
fr Pattern t r
p = Identity (Pattern t' r') -> Pattern t' r'
forall a. Identity a -> a
runIdentity (Identity (Pattern t' r') -> Pattern t' r')
-> (Pattern t r -> Identity (Pattern t' r'))
-> Pattern t r
-> Pattern t' r'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> Identity t')
-> (r -> Identity r') -> Pattern t r -> Identity (Pattern t' r')
forall (m :: * -> *) t t' r r'.
Applicative m =>
(t -> m t') -> (r -> m r') -> Pattern t r -> m (Pattern t' r')
rmapPatternM (t' -> Identity t'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (t' -> Identity t') -> (t -> t') -> t -> Identity t'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> t'
ft) (r' -> Identity r'
forall a. a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (r' -> Identity r') -> (r -> r') -> r -> Identity r'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> r'
fr) (Pattern t r -> Pattern t' r') -> Pattern t r -> Pattern t' r'
forall a b. (a -> b) -> a -> b
$ Pattern t r
p

rmapPatternM :: (Applicative m) => (t -> m t') -> (r -> m r') -> Pattern t r -> m (Pattern t' r')
rmapPatternM :: forall (m :: * -> *) t t' r r'.
Applicative m =>
(t -> m t') -> (r -> m r') -> Pattern t r -> m (Pattern t' r')
rmapPatternM t -> m t'
ft r -> m r'
fr = Pattern t r -> m (Pattern t' r')
go
  where
    go :: Pattern t r -> m (Pattern t' r')
go = \case
      Pattern t r
PUnbound -> Pattern t' r' -> m (Pattern t' r')
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern t' r' -> m (Pattern t' r'))
-> Pattern t' r' -> m (Pattern t' r')
forall a b. (a -> b) -> a -> b
$ Pattern t' r'
forall t r. Pattern t r
PUnbound
      Pattern t r
PVar -> Pattern t' r' -> m (Pattern t' r')
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern t' r' -> m (Pattern t' r'))
-> Pattern t' r' -> m (Pattern t' r')
forall a b. (a -> b) -> a -> b
$ Pattern t' r'
forall t r. Pattern t r
PVar
      PBoolean Bool
b -> Pattern t' r' -> m (Pattern t' r')
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern t' r' -> m (Pattern t' r'))
-> Pattern t' r' -> m (Pattern t' r')
forall a b. (a -> b) -> a -> b
$ Bool -> Pattern t' r'
forall t r. Bool -> Pattern t r
PBoolean Bool
b
      PInt Int64
i -> Pattern t' r' -> m (Pattern t' r')
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern t' r' -> m (Pattern t' r'))
-> Pattern t' r' -> m (Pattern t' r')
forall a b. (a -> b) -> a -> b
$ Int64 -> Pattern t' r'
forall t r. Int64 -> Pattern t r
PInt Int64
i
      PNat Word64
n -> Pattern t' r' -> m (Pattern t' r')
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern t' r' -> m (Pattern t' r'))
-> Pattern t' r' -> m (Pattern t' r')
forall a b. (a -> b) -> a -> b
$ Word64 -> Pattern t' r'
forall t r. Word64 -> Pattern t r
PNat Word64
n
      PFloat Double
d -> Pattern t' r' -> m (Pattern t' r')
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern t' r' -> m (Pattern t' r'))
-> Pattern t' r' -> m (Pattern t' r')
forall a b. (a -> b) -> a -> b
$ Double -> Pattern t' r'
forall t r. Double -> Pattern t r
PFloat Double
d
      PText t
t -> t' -> Pattern t' r'
forall t r. t -> Pattern t r
PText (t' -> Pattern t' r') -> m t' -> m (Pattern t' r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t -> m t'
ft t
t
      PChar Char
c -> Pattern t' r' -> m (Pattern t' r')
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern t' r' -> m (Pattern t' r'))
-> Pattern t' r' -> m (Pattern t' r')
forall a b. (a -> b) -> a -> b
$ Char -> Pattern t' r'
forall t r. Char -> Pattern t r
PChar Char
c
      PConstructor r
r Word64
i [Pattern t r]
ps -> r' -> Word64 -> [Pattern t' r'] -> Pattern t' r'
forall t r. r -> Word64 -> [Pattern t r] -> Pattern t r
PConstructor (r' -> Word64 -> [Pattern t' r'] -> Pattern t' r')
-> m r' -> m (Word64 -> [Pattern t' r'] -> Pattern t' r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> r -> m r'
fr r
r m (Word64 -> [Pattern t' r'] -> Pattern t' r')
-> m Word64 -> m ([Pattern t' r'] -> Pattern t' r')
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64 -> m Word64
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64
i m ([Pattern t' r'] -> Pattern t' r')
-> m [Pattern t' r'] -> m (Pattern t' r')
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Pattern t r -> m (Pattern t' r'))
-> [Pattern t r] -> m [Pattern t' r']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Pattern t r -> m (Pattern t' r')
go [Pattern t r]
ps)
      PAs Pattern t r
p -> Pattern t' r' -> Pattern t' r'
forall t r. Pattern t r -> Pattern t r
PAs (Pattern t' r' -> Pattern t' r')
-> m (Pattern t' r') -> m (Pattern t' r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern t r -> m (Pattern t' r')
go Pattern t r
p
      PEffectPure Pattern t r
p -> Pattern t' r' -> Pattern t' r'
forall t r. Pattern t r -> Pattern t r
PEffectPure (Pattern t' r' -> Pattern t' r')
-> m (Pattern t' r') -> m (Pattern t' r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern t r -> m (Pattern t' r')
go Pattern t r
p
      PEffectBind r
r Word64
i [Pattern t r]
ps Pattern t r
p -> r' -> Word64 -> [Pattern t' r'] -> Pattern t' r' -> Pattern t' r'
forall t r.
r -> Word64 -> [Pattern t r] -> Pattern t r -> Pattern t r
PEffectBind (r' -> Word64 -> [Pattern t' r'] -> Pattern t' r' -> Pattern t' r')
-> m r'
-> m (Word64 -> [Pattern t' r'] -> Pattern t' r' -> Pattern t' r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> r -> m r'
fr r
r m (Word64 -> [Pattern t' r'] -> Pattern t' r' -> Pattern t' r')
-> m Word64
-> m ([Pattern t' r'] -> Pattern t' r' -> Pattern t' r')
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64 -> m Word64
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64
i m ([Pattern t' r'] -> Pattern t' r' -> Pattern t' r')
-> m [Pattern t' r'] -> m (Pattern t' r' -> Pattern t' r')
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Pattern t r -> m (Pattern t' r'))
-> [Pattern t r] -> m [Pattern t' r']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Pattern t r -> m (Pattern t' r')
go [Pattern t r]
ps m (Pattern t' r' -> Pattern t' r')
-> m (Pattern t' r') -> m (Pattern t' r')
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Pattern t r -> m (Pattern t' r')
go Pattern t r
p
      PSequenceLiteral [Pattern t r]
ps -> [Pattern t' r'] -> Pattern t' r'
forall t r. [Pattern t r] -> Pattern t r
PSequenceLiteral ([Pattern t' r'] -> Pattern t' r')
-> m [Pattern t' r'] -> m (Pattern t' r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Pattern t r -> m (Pattern t' r'))
-> [Pattern t r] -> m [Pattern t' r']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Pattern t r -> m (Pattern t' r')
go [Pattern t r]
ps
      PSequenceOp Pattern t r
p1 SeqOp
op Pattern t r
p2 -> Pattern t' r' -> SeqOp -> Pattern t' r' -> Pattern t' r'
forall t r. Pattern t r -> SeqOp -> Pattern t r -> Pattern t r
PSequenceOp (Pattern t' r' -> SeqOp -> Pattern t' r' -> Pattern t' r')
-> m (Pattern t' r') -> m (SeqOp -> Pattern t' r' -> Pattern t' r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern t r -> m (Pattern t' r')
go Pattern t r
p1 m (SeqOp -> Pattern t' r' -> Pattern t' r')
-> m SeqOp -> m (Pattern t' r' -> Pattern t' r')
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SeqOp -> m SeqOp
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SeqOp
op m (Pattern t' r' -> Pattern t' r')
-> m (Pattern t' r') -> m (Pattern t' r')
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Pattern t r -> m (Pattern t' r')
go Pattern t r
p2

dependencies ::
  (Ord termRef, Ord typeRef, Ord termLink, Ord typeLink, Ord v) =>
  ABT.Term (F' text termRef typeRef termLink typeLink vt) v a ->
  (Set termRef, Set typeRef, Set termLink, Set typeLink)
dependencies :: forall termRef typeRef termLink typeLink v text vt a.
(Ord termRef, Ord typeRef, Ord termLink, Ord typeLink, Ord v) =>
Term (F' text termRef typeRef termLink typeLink vt) v a
-> (Set termRef, Set typeRef, Set termLink, Set typeLink)
dependencies =
  Writer
  (Set termRef, Set typeRef, Set termLink, Set typeLink)
  (Term (F' text termRef typeRef termLink typeLink vt) v a)
-> (Set termRef, Set typeRef, Set termLink, Set typeLink)
forall w a. Writer w a -> w
Writer.execWriter (Writer
   (Set termRef, Set typeRef, Set termLink, Set typeLink)
   (Term (F' text termRef typeRef termLink typeLink vt) v a)
 -> (Set termRef, Set typeRef, Set termLink, Set typeLink))
-> (Term (F' text termRef typeRef termLink typeLink vt) v a
    -> Writer
         (Set termRef, Set typeRef, Set termLink, Set typeLink)
         (Term (F' text termRef typeRef termLink typeLink vt) v a))
-> Term (F' text termRef typeRef termLink typeLink vt) v a
-> (Set termRef, Set typeRef, Set termLink, Set typeLink)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (F'
   text
   termRef
   typeRef
   termLink
   typeLink
   vt
   (Term (F' text termRef typeRef termLink typeLink vt) v a)
 -> WriterT
      (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ())
-> Term (F' text termRef typeRef termLink typeLink vt) v a
-> Writer
     (Set termRef, Set typeRef, Set termLink, Set typeLink)
     (Term (F' text termRef typeRef termLink typeLink vt) v a)
forall (f :: * -> *) (g :: * -> *) v a.
(Traversable f, Applicative g, Ord v) =>
(f (Term f v a) -> g ()) -> Term f v a -> g (Term f v a)
ABT.visit_ \case
    Ref termRef
r -> termRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {a} {b} {c} {d} {m :: * -> *}.
(MonadWriter (Set a, b, c, d) m, Monoid b, Monoid c, Monoid d,
 Ord a) =>
a -> m ()
termRef termRef
r
    Constructor typeRef
r Word64
_ -> typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {a} {a} {c} {d} {m :: * -> *}.
(MonadWriter (a, Set a, c, d) m, Monoid a, Monoid c, Monoid d,
 Ord a) =>
a -> m ()
typeRef typeRef
r
    Request typeRef
r Word64
_ -> typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {a} {a} {c} {d} {m :: * -> *}.
(MonadWriter (a, Set a, c, d) m, Monoid a, Monoid c, Monoid d,
 Ord a) =>
a -> m ()
typeRef typeRef
r
    Match Term (F' text termRef typeRef termLink typeLink vt) v a
_ [MatchCase
   text
   typeRef
   (Term (F' text termRef typeRef termLink typeLink vt) v a)]
cases -> [MatchCase
   text
   typeRef
   (Term (F' text termRef typeRef termLink typeLink vt) v a)]
-> (MatchCase
      text
      typeRef
      (Term (F' text termRef typeRef termLink typeLink vt) v a)
    -> WriterT
         (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ())
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
Foldable.for_ [MatchCase
   text
   typeRef
   (Term (F' text termRef typeRef termLink typeLink vt) v a)]
cases \case
      MatchCase Pattern text typeRef
pat Maybe (Term (F' text termRef typeRef termLink typeLink vt) v a)
_guard Term (F' text termRef typeRef termLink typeLink vt) v a
_body -> Pattern text typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {t}.
Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go Pattern text typeRef
pat
        where
          go :: Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go = \case
            PConstructor typeRef
r Word64
_i [Pattern t typeRef]
args -> typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {a} {a} {c} {d} {m :: * -> *}.
(MonadWriter (a, Set a, c, d) m, Monoid a, Monoid c, Monoid d,
 Ord a) =>
a -> m ()
typeRef typeRef
r WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall a b.
WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity a
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Pattern t typeRef
 -> WriterT
      (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ())
-> [Pattern t typeRef]
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
Foldable.traverse_ Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go [Pattern t typeRef]
args
            PAs Pattern t typeRef
pat -> Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go Pattern t typeRef
pat
            PEffectPure Pattern t typeRef
pat -> Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go Pattern t typeRef
pat
            PEffectBind typeRef
r Word64
_i [Pattern t typeRef]
args Pattern t typeRef
k -> typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {a} {a} {c} {d} {m :: * -> *}.
(MonadWriter (a, Set a, c, d) m, Monoid a, Monoid c, Monoid d,
 Ord a) =>
a -> m ()
typeRef typeRef
r WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall a b.
WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity a
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Pattern t typeRef
 -> WriterT
      (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ())
-> [Pattern t typeRef]
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
Foldable.traverse_ Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go [Pattern t typeRef]
args WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall a b.
WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity a
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go Pattern t typeRef
k
            PSequenceLiteral [Pattern t typeRef]
pats -> (Pattern t typeRef
 -> WriterT
      (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ())
-> [Pattern t typeRef]
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
Foldable.traverse_ Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go [Pattern t typeRef]
pats
            PSequenceOp Pattern t typeRef
l SeqOp
_op Pattern t typeRef
r -> Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go Pattern t typeRef
l WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall a b.
WriterT
  (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity a
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Pattern t typeRef
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
go Pattern t typeRef
r
            Pattern t typeRef
_ -> ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall a.
a
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
    TermLink termLink
r -> termLink
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {a} {b} {a} {d} {m :: * -> *}.
(MonadWriter (a, b, Set a, d) m, Monoid a, Monoid b, Monoid d,
 Ord a) =>
a -> m ()
termLink termLink
r
    TypeLink typeLink
r -> typeLink
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall {a} {b} {c} {a} {m :: * -> *}.
(MonadWriter (a, b, c, Set a) m, Monoid a, Monoid b, Monoid c,
 Ord a) =>
a -> m ()
typeLink typeLink
r
    F'
  text
  termRef
  typeRef
  termLink
  typeLink
  vt
  (Term (F' text termRef typeRef termLink typeLink vt) v a)
_ -> ()
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity ()
forall a.
a
-> WriterT
     (Set termRef, Set typeRef, Set termLink, Set typeLink) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
  where
    termRef :: a -> m ()
termRef a
r = (Set a, b, c, d) -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Writer.tell (a -> Set a
forall a. a -> Set a
Set.singleton a
r, b
forall a. Monoid a => a
mempty, c
forall a. Monoid a => a
mempty, d
forall a. Monoid a => a
mempty)
    typeRef :: a -> m ()
typeRef a
r = (a, Set a, c, d) -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Writer.tell (a
forall a. Monoid a => a
mempty, a -> Set a
forall a. a -> Set a
Set.singleton a
r, c
forall a. Monoid a => a
mempty, d
forall a. Monoid a => a
mempty)
    termLink :: a -> m ()
termLink a
r = (a, b, Set a, d) -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Writer.tell (a
forall a. Monoid a => a
mempty, b
forall a. Monoid a => a
mempty, a -> Set a
forall a. a -> Set a
Set.singleton a
r, d
forall a. Monoid a => a
mempty)
    typeLink :: a -> m ()
typeLink a
r = (a, b, c, Set a) -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Writer.tell (a
forall a. Monoid a => a
mempty, b
forall a. Monoid a => a
mempty, c
forall a. Monoid a => a
mempty, a -> Set a
forall a. a -> Set a
Set.singleton a
r)

-- | Given the pieces of a single term component,
-- replaces all 'Nothing' self-referential hashes with a variable reference
-- to the relevant piece of the component in the component map.
unhashComponent ::
  forall v extra.
  (ABT.Var v) =>
  -- | The hash of the component, this is used to fill in self-references.
  Hash ->
  -- | A function to convert a reference to a variable. The actual var names aren't important.
  (Reference.Id -> v) ->
  -- A SINGLE term component. Self references should have a 'Nothing' hash in term
  -- references/term links
  Map Reference.Id (Term v, extra) ->
  -- | The component with all self-references replaced with variable references.
  Map Reference.Id (v, HashableTerm v, extra)
unhashComponent :: forall v extra.
Var v =>
Hash
-> (Id -> v)
-> Map Id (Term v, extra)
-> Map Id (v, HashableTerm v, extra)
unhashComponent Hash
componentHash Id -> v
refToVar Map Id (Term v, extra)
m =
  Map Id (v, Term v, extra)
withGeneratedVars
    Map Id (v, Term v, extra)
-> (Map Id (v, Term v, extra) -> Map Id (v, HashableTerm v, extra))
-> Map Id (v, HashableTerm v, extra)
forall a b. a -> (a -> b) -> b
& ((v, Term v, extra) -> Identity (v, HashableTerm v, extra))
-> Map Id (v, Term v, extra)
-> Identity (Map Id (v, HashableTerm v, extra))
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal
  Int
  (Map Id (v, Term v, extra))
  (Map Id (v, HashableTerm v, extra))
  (v, Term v, extra)
  (v, HashableTerm v, extra)
traversed (((v, Term v, extra) -> Identity (v, HashableTerm v, extra))
 -> Map Id (v, Term v, extra)
 -> Identity (Map Id (v, HashableTerm v, extra)))
-> ((Term v -> Identity (HashableTerm v))
    -> (v, Term v, extra) -> Identity (v, HashableTerm v, extra))
-> (Term v -> Identity (HashableTerm v))
-> Map Id (v, Term v, extra)
-> Identity (Map Id (v, HashableTerm v, extra))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term v -> Identity (HashableTerm v))
-> (v, Term v, extra) -> Identity (v, HashableTerm v, extra)
forall s t a b. Field2 s t a b => Lens s t a b
Lens
  (v, Term v, extra)
  (v, HashableTerm v, extra)
  (Term v)
  (HashableTerm v)
_2 ((Term v -> Identity (HashableTerm v))
 -> Map Id (v, Term v, extra)
 -> Identity (Map Id (v, HashableTerm v, extra)))
-> (Term v -> HashableTerm v)
-> Map Id (v, Term v, extra)
-> Map Id (v, HashableTerm v, extra)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Term v -> HashableTerm v
fillSelfReferences
  where
    usedVars :: Set v
    usedVars :: Set v
usedVars = ((Term v, extra) -> Set v) -> Map Id (Term v, extra) -> Set v
forall m a. Monoid m => (a -> m) -> Map Id a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ([v] -> Set v
forall a. Ord a => [a] -> Set a
Set.fromList ([v] -> Set v)
-> ((Term v, extra) -> [v]) -> (Term v, extra) -> Set v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term v -> [v]
forall (f :: * -> *) v a. Foldable f => Term f v a -> [v]
ABT.allVars (Term v -> [v])
-> ((Term v, extra) -> Term v) -> (Term v, extra) -> [v]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term v, extra) -> Term v
forall a b. (a, b) -> a
fst) Map Id (Term v, extra)
m
    withGeneratedVars :: Map Reference.Id (v, Term v, extra)
    withGeneratedVars :: Map Id (v, Term v, extra)
withGeneratedVars = State (Set v) (Map Id (v, Term v, extra))
-> Set v -> Map Id (v, Term v, extra)
forall s a. State s a -> s -> a
evalState ((Id
 -> (Term v, extra) -> StateT (Set v) Identity (v, Term v, extra))
-> Map Id (Term v, extra)
-> State (Set v) (Map Id (v, Term v, extra))
forall (t :: * -> *) k a b.
Applicative t =>
(k -> a -> t b) -> Map k a -> t (Map k b)
Map.traverseWithKey Id -> (Term v, extra) -> StateT (Set v) Identity (v, Term v, extra)
forall trm.
Id -> (trm, extra) -> StateT (Set v) Identity (v, trm, extra)
assignVar Map Id (Term v, extra)
m) Set v
usedVars
    assignVar :: Reference.Id -> (trm, extra) -> StateT (Set v) Identity (v, trm, extra)
    assignVar :: forall trm.
Id -> (trm, extra) -> StateT (Set v) Identity (v, trm, extra)
assignVar Id
r (trm
trm, extra
extra) = (,trm
trm,extra
extra) (v -> (v, trm, extra))
-> StateT (Set v) Identity v
-> StateT (Set v) Identity (v, trm, extra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> v -> StateT (Set v) Identity v
forall v (m :: * -> *). (Var v, MonadState (Set v) m) => v -> m v
ABT.freshenS (Id -> v
refToVar Id
r)
    fillSelfReferences :: Term v -> HashableTerm v
    fillSelfReferences :: Term v -> HashableTerm v
fillSelfReferences = Algebra (Term' (F v) v ()) (HashableTerm v)
-> Term v -> HashableTerm v
forall a. Algebra (Term' (F v) v ()) a -> Term v -> a
forall t (f :: * -> *) a. Recursive t f => Algebra f a -> t -> a
cata Algebra (Term' (F v) v ()) (HashableTerm v)
alg
      where
        rewriteTermReference :: Reference.Id' (Maybe Hash) -> Either v Reference.Reference
        rewriteTermReference :: Id' (Maybe Hash) -> Either v HashableTermRef
rewriteTermReference rid :: Id' (Maybe Hash)
rid@(Reference.Id Maybe Hash
mayH Word64
pos) =
          case Maybe Hash
mayH of
            Just Hash
h ->
              case Id -> Map Id (v, Term v, extra) -> Maybe (v, Term v, extra)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (Hash -> Word64 -> Id
forall h. h -> Word64 -> Id' h
Reference.Id Hash
h Word64
pos) Map Id (v, Term v, extra)
withGeneratedVars of
                -- No entry in the component map, so this is NOT a self-reference, keep it but
                -- replace the 'Maybe Hash' with a 'Hash'.
                Maybe (v, Term v, extra)
Nothing -> HashableTermRef -> Either v HashableTermRef
forall a b. b -> Either a b
Right (Id -> HashableTermRef
forall t h. Id' h -> Reference' t h
Reference.ReferenceDerived (Hash -> Word64 -> Id
forall h. h -> Word64 -> Id' h
Reference.Id Hash
h Word64
pos))
                -- Entry in the component map, so this is a self-reference, replace it with a
                -- Var.
                Just (v
v, Term v
_, extra
_) -> v -> Either v HashableTermRef
forall a b. a -> Either a b
Left v
v
            Maybe Hash
Nothing ->
              -- This is a self-reference, so we expect to find it in the component map.
              case Id -> Map Id (v, Term v, extra) -> Maybe (v, Term v, extra)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (Hash -> Maybe Hash -> Hash
forall a. a -> Maybe a -> a
fromMaybe Hash
componentHash (Maybe Hash -> Hash) -> Id' (Maybe Hash) -> Id
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Id' (Maybe Hash)
rid) Map Id (v, Term v, extra)
withGeneratedVars of
                Maybe (v, Term v, extra)
Nothing -> String -> Either v HashableTermRef
forall a. HasCallStack => String -> a
error String
"unhashComponent: self-reference not found in component map"
                Just (v
v, Term v
_, extra
_) -> v -> Either v HashableTermRef
forall a b. a -> Either a b
Left v
v
        alg :: ABT.Term' (F v) v () (HashableTerm v) -> HashableTerm v
        alg :: Algebra (Term' (F v) v ()) (HashableTerm v)
alg (ABT.Term' Set v
_ () ABT (F v) v (HashableTerm v)
abt) = case ABT (F v) v (HashableTerm v)
abt of
          ABT.Var v
v -> () -> v -> HashableTerm v
forall a v (f :: * -> *). a -> v -> Term f v a
ABT.var () v
v
          ABT.Cycle HashableTerm v
body -> () -> HashableTerm v -> HashableTerm v
forall a (f :: * -> *) v. a -> Term f v a -> Term f v a
ABT.cycle () HashableTerm v
body
          ABT.Abs v
v HashableTerm v
body -> () -> v -> HashableTerm v -> HashableTerm v
forall v a (f :: * -> *).
Ord v =>
a -> v -> Term f v a -> Term f v a
ABT.abs () v
v HashableTerm v
body
          ABT.Tm F v (HashableTerm v)
t -> case F v (HashableTerm v)
t of
            -- Check refs to see if they refer to the current component, replace them with
            -- vars if they do.
            (Ref (Reference.ReferenceDerived Id' (Maybe Hash)
rid)) ->
              Id' (Maybe Hash) -> Either v HashableTermRef
rewriteTermReference Id' (Maybe Hash)
rid
                Either v HashableTermRef
-> (Either v HashableTermRef -> HashableTerm v) -> HashableTerm v
forall a b. a -> (a -> b) -> b
& (v -> HashableTerm v)
-> (HashableTermRef -> HashableTerm v)
-> Either v HashableTermRef
-> HashableTerm v
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (() -> v -> HashableTerm v
forall a v (f :: * -> *). a -> v -> Term f v a
ABT.var ()) (()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> (HashableTermRef
    -> F'
         Text
         HashableTermRef
         HashableTermRef
         HashableTermLink
         HashableTermRef
         v
         (HashableTerm v))
-> HashableTermRef
-> HashableTerm v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashableTermRef
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
termRef -> F' text termRef typeRef termLink typeLink vt a
Ref)
            (Ref (Reference.ReferenceBuiltin Text
t)) ->
              ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTermRef
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
termRef -> F' text termRef typeRef termLink typeLink vt a
Ref (Text -> HashableTermRef
forall t h. t -> Reference' t h
Reference.ReferenceBuiltin Text
t)
            TermLink TermLink
referent -> case TermLink
referent of
              Referent.Ref (Reference.ReferenceDerived Id' (Maybe Hash)
rid) ->
                Id' (Maybe Hash) -> Either v HashableTermRef
rewriteTermReference Id' (Maybe Hash)
rid
                  Either v HashableTermRef
-> (Either v HashableTermRef -> HashableTerm v) -> HashableTerm v
forall a b. a -> (a -> b) -> b
& (v -> HashableTerm v)
-> (HashableTermRef -> HashableTerm v)
-> Either v HashableTermRef
-> HashableTerm v
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (() -> v -> HashableTerm v
forall a v (f :: * -> *). a -> v -> Term f v a
ABT.var ()) (()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> (HashableTermRef
    -> F'
         Text
         HashableTermRef
         HashableTermRef
         HashableTermLink
         HashableTermRef
         v
         (HashableTerm v))
-> HashableTermRef
-> HashableTerm v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashableTermLink
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
termLink -> F' text termRef typeRef termLink typeLink vt a
TermLink (HashableTermLink
 -> F'
      Text
      HashableTermRef
      HashableTermRef
      HashableTermLink
      HashableTermRef
      v
      (HashableTerm v))
-> (HashableTermRef -> HashableTermLink)
-> HashableTermRef
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashableTermRef -> HashableTermLink
forall termRef typeRef. termRef -> Referent' termRef typeRef
Referent.Ref)
              Referent.Ref (Reference.ReferenceBuiltin Text
t) ->
                ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTermLink
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
termLink -> F' text termRef typeRef termLink typeLink vt a
TermLink (HashableTermRef -> HashableTermLink
forall termRef typeRef. termRef -> Referent' termRef typeRef
Referent.Ref (Text -> HashableTermRef
forall t h. t -> Reference' t h
Reference.ReferenceBuiltin Text
t))
              Referent.Con HashableTermRef
typeRef Word64
conId -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTermLink
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
termLink -> F' text termRef typeRef termLink typeLink vt a
TermLink (HashableTermRef -> Word64 -> HashableTermLink
forall termRef typeRef.
typeRef -> Word64 -> Referent' termRef typeRef
Referent.Con HashableTermRef
typeRef Word64
conId)
            -- All other cases are unchanged, but we need to manually reconstruct them to
            -- safely coerce the term types.
            Int Int64
i -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ Int64
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
Int64 -> F' text termRef typeRef termLink typeLink vt a
Int Int64
i
            Nat Word64
n -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ Word64
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
Word64 -> F' text termRef typeRef termLink typeLink vt a
Nat Word64
n
            Float Double
d -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ Double
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
Double -> F' text termRef typeRef termLink typeLink vt a
Float Double
d
            Boolean Bool
b -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ Bool
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
Bool -> F' text termRef typeRef termLink typeLink vt a
Boolean Bool
b
            Text Text
t -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ Text
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
text -> F' text termRef typeRef termLink typeLink vt a
Text Text
t
            Char Char
c -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ Char
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
Char -> F' text termRef typeRef termLink typeLink vt a
Char Char
c
            Constructor HashableTermRef
typeRef Word64
conId -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTermRef
-> Word64
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
typeRef -> Word64 -> F' text termRef typeRef termLink typeLink vt a
Constructor HashableTermRef
typeRef Word64
conId
            Request HashableTermRef
typeRef Word64
conId -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTermRef
-> Word64
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
typeRef -> Word64 -> F' text termRef typeRef termLink typeLink vt a
Request HashableTermRef
typeRef Word64
conId
            Handle HashableTerm v
e HashableTerm v
h -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
Handle HashableTerm v
e HashableTerm v
h
            App HashableTerm v
f HashableTerm v
a -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
App HashableTerm v
f HashableTerm v
a
            Ann HashableTerm v
a TypeR HashableTermRef v
typ -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> TypeR HashableTermRef v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a
-> TypeR typeRef vt
-> F' text termRef typeRef termLink typeLink vt a
Ann HashableTerm v
a TypeR HashableTermRef v
typ
            List Seq (HashableTerm v)
s -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ Seq (HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
Seq a -> F' text termRef typeRef termLink typeLink vt a
List Seq (HashableTerm v)
s
            If HashableTerm v
c HashableTerm v
t HashableTerm v
f -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> HashableTerm v
-> HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a -> a -> a -> F' text termRef typeRef termLink typeLink vt a
If HashableTerm v
c HashableTerm v
t HashableTerm v
f
            And HashableTerm v
p HashableTerm v
q -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
And HashableTerm v
p HashableTerm v
q
            Or HashableTerm v
p HashableTerm v
q -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
Or HashableTerm v
p HashableTerm v
q
            Lam HashableTerm v
b -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a -> F' text termRef typeRef termLink typeLink vt a
Lam HashableTerm v
b
            LetRec [HashableTerm v]
bs HashableTerm v
b -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ [HashableTerm v]
-> HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
[a] -> a -> F' text termRef typeRef termLink typeLink vt a
LetRec [HashableTerm v]
bs HashableTerm v
b
            Let HashableTerm v
a HashableTerm v
b -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> HashableTerm v
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a -> a -> F' text termRef typeRef termLink typeLink vt a
Let HashableTerm v
a HashableTerm v
b
            Match HashableTerm v
s [MatchCase Text HashableTermRef (HashableTerm v)]
cases -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTerm v
-> [MatchCase Text HashableTermRef (HashableTerm v)]
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
a
-> [MatchCase text typeRef a]
-> F' text termRef typeRef termLink typeLink vt a
Match HashableTerm v
s [MatchCase Text HashableTermRef (HashableTerm v)]
cases
            TypeLink HashableTermRef
r -> ()
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall (f :: * -> *) v a.
(Foldable f, Ord v) =>
a -> f (Term f v a) -> Term f v a
ABT.tm () (F'
   Text
   HashableTermRef
   HashableTermRef
   HashableTermLink
   HashableTermRef
   v
   (HashableTerm v)
 -> HashableTerm v)
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
-> HashableTerm v
forall a b. (a -> b) -> a -> b
$ HashableTermRef
-> F'
     Text
     HashableTermRef
     HashableTermRef
     HashableTermLink
     HashableTermRef
     v
     (HashableTerm v)
forall text termRef typeRef termLink typeLink vt a.
typeLink -> F' text termRef typeRef termLink typeLink vt a
TypeLink HashableTermRef
r