{-# LANGUAGE OverloadedStrings #-}

module Hydra.Sources.Tier1.Tier1 where

-- Standard Tier-1 imports
import           Prelude hiding ((++))
import qualified Data.List                 as L
import qualified Data.Map                  as M
import qualified Data.Set                  as S
import qualified Data.Maybe                as Y
import           Hydra.Dsl.Base            as Base
import qualified Hydra.Dsl.Core            as Core
import qualified Hydra.Dsl.Graph           as Graph
import qualified Hydra.Dsl.Lib.Equality    as Equality
import qualified Hydra.Dsl.Lib.Flows       as Flows
import qualified Hydra.Dsl.Lib.Io          as Io
import qualified Hydra.Dsl.Lib.Lists       as Lists
import qualified Hydra.Dsl.Lib.Literals    as Literals
import qualified Hydra.Dsl.Lib.Logic       as Logic
import qualified Hydra.Dsl.Lib.Maps        as Maps
import qualified Hydra.Dsl.Lib.Math        as Math
import qualified Hydra.Dsl.Lib.Optionals   as Optionals
import qualified Hydra.Dsl.Lib.Sets        as Sets
import           Hydra.Dsl.Lib.Strings     as Strings
import qualified Hydra.Dsl.Module          as Module
import qualified Hydra.Dsl.Terms           as Terms
import qualified Hydra.Dsl.Types           as Types
import           Hydra.Sources.Tier0.All

import Hydra.Sources.Tier1.Constants
import Hydra.Sources.Tier1.Strip
import Hydra.Dsl.Mantle


tier1Definition :: String -> TTerm a -> TElement a
tier1Definition :: forall a. String -> TTerm a -> TElement a
tier1Definition = Module -> String -> TTerm a -> TElement a
forall a. Module -> String -> TTerm a -> TElement a
definitionInModule Module
hydraTier1Module

hydraTier1Module :: Module
hydraTier1Module :: Module
hydraTier1Module = Namespace
-> [Element] -> [Module] -> [Module] -> Maybe String -> Module
Module (String -> Namespace
Namespace String
"hydra/tier1") [Element]
elements
    [Module
hydraComputeModule, Module
hydraConstantsModule, Module
hydraStripModule] [Module]
tier0Modules (Maybe String -> Module) -> Maybe String -> Module
forall a b. (a -> b) -> a -> b
$
    String -> Maybe String
forall a. a -> Maybe a
Just (String
"A module for miscellaneous tier-1 functions and constants.")
  where
   elements :: [Element]
elements = [
     TElement (Double -> Double) -> Element
forall a. TElement a -> Element
el TElement (Double -> Double)
floatValueToBigfloatDef,
     TElement (IntegerValue -> Integer) -> Element
forall a. TElement a -> Element
el TElement (IntegerValue -> Integer)
integerValueToBigintDef,
     TElement (Term -> Bool) -> Element
forall a. TElement a -> Element
el TElement (Term -> Bool)
isLambdaDef,
     TElement (QualifiedName -> Name) -> Element
forall a. TElement a -> Element
el TElement (QualifiedName -> Name)
unqualifyNameDef,
     -- Rewriting.hs
     TElement
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
-> Element
forall a. TElement a -> Element
el TElement
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
forall x.
TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
foldOverTermDef,
     TElement
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
-> Element
forall a. TElement a -> Element
el TElement
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
forall x.
TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
foldOverTypeDef,
     TElement (Term -> Set Name) -> Element
forall a. TElement a -> Element
el TElement (Term -> Set Name)
freeVariablesInTermDef,
     TElement (Type -> Set Name) -> Element
forall a. TElement a -> Element
el TElement (Type -> Set Name)
freeVariablesInTypeDef,
     TElement (Term -> [Term]) -> Element
forall a. TElement a -> Element
el TElement (Term -> [Term])
subtermsDef,
     TElement (Term -> [(TermAccessor, Term)]) -> Element
forall a. TElement a -> Element
el TElement (Term -> [(TermAccessor, Term)])
subtermsWithAccessorsDef,
     TElement (Type -> [Type]) -> Element
forall a. TElement a -> Element
el TElement (Type -> [Type])
subtypesDef,
     -- Flows.hs
     TElement Trace -> Element
forall a. TElement a -> Element
el TElement Trace
emptyTraceDef,
     TElement (Flow Any Any -> Bool) -> Element
forall a. TElement a -> Element
el TElement (Flow Any Any -> Bool)
forall s a. TElement (Flow s a -> Bool)
flowSucceedsDef,
     TElement (Any -> Any -> Flow Any Any -> Any) -> Element
forall a. TElement a -> Element
el TElement (Any -> Any -> Flow Any Any -> Any)
forall a s. TElement (a -> s -> Flow s a -> a)
fromFlowDef,
     TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
-> Element
forall a. TElement a -> Element
el TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
forall s a.
TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
mutateTraceDef,
     TElement (String -> Trace -> Trace) -> Element
forall a. TElement a -> Element
el TElement (String -> Trace -> Trace)
pushErrorDef,
     TElement (String -> Flow Any Any -> Flow Any Any) -> Element
forall a. TElement a -> Element
el TElement (String -> Flow Any Any -> Flow Any Any)
forall s a. TElement (String -> Flow s a -> Flow s a)
warnDef,
     TElement (String -> Flow Any Any -> Flow Any Any) -> Element
forall a. TElement a -> Element
el TElement (String -> Flow Any Any -> Flow Any Any)
forall s a. TElement (String -> Flow s a -> Flow s a)
withFlagDef,
     TElement (Any -> Flow Any Any -> Flow Any Any) -> Element
forall a. TElement a -> Element
el TElement (Any -> Flow Any Any -> Flow Any Any)
forall s1 a s2. TElement (s1 -> Flow s1 a -> Flow s2 a)
withStateDef,
     TElement (String -> Flow Any Any -> Flow Any Any) -> Element
forall a. TElement a -> Element
el TElement (String -> Flow Any Any -> Flow Any Any)
forall s a. TElement (String -> Flow s a -> Flow s a)
withTraceDef
     ]

floatValueToBigfloatDef :: TElement (Double -> Double)
floatValueToBigfloatDef :: TElement (Double -> Double)
floatValueToBigfloatDef = String -> TTerm (Double -> Double) -> TElement (Double -> Double)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"floatValueToBigfloat" (TTerm (Double -> Double) -> TElement (Double -> Double))
-> TTerm (Double -> Double) -> TElement (Double -> Double)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Double -> Double) -> TTerm (Double -> Double)
forall a. String -> TTerm a -> TTerm a
doc String
"Convert a floating-point value of any precision to a bigfloat" (TTerm (Double -> Double) -> TTerm (Double -> Double))
-> TTerm (Double -> Double) -> TTerm (Double -> Double)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type -> TTerm (Double -> Double) -> TTerm (Double -> Double)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
floatValueT Type
Types.bigfloat (TTerm (Double -> Double) -> TTerm (Double -> Double))
-> TTerm (Double -> Double) -> TTerm (Double -> Double)
forall a b. (a -> b) -> a -> b
$
  Name -> Maybe (TTerm Double) -> [Field] -> TTerm (Double -> Double)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_FloatValue Maybe (TTerm Double)
forall a. Maybe a
Nothing [
    Name
_FloatValue_bigfloatName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Any -> Any)
forall x. TTerm (x -> x)
Equality.identity,
    Name
_FloatValue_float32Name -> TTerm (Float -> Double) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Float -> Double)
Literals.float32ToBigfloat,
    Name
_FloatValue_float64Name -> TTerm (Double -> Double) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Double -> Double)
Literals.float64ToBigfloat]

integerValueToBigintDef :: TElement (IntegerValue -> Integer)
integerValueToBigintDef :: TElement (IntegerValue -> Integer)
integerValueToBigintDef = String
-> TTerm (IntegerValue -> Integer)
-> TElement (IntegerValue -> Integer)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"integerValueToBigint" (TTerm (IntegerValue -> Integer)
 -> TElement (IntegerValue -> Integer))
-> TTerm (IntegerValue -> Integer)
-> TElement (IntegerValue -> Integer)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (IntegerValue -> Integer)
-> TTerm (IntegerValue -> Integer)
forall a. String -> TTerm a -> TTerm a
doc String
"Convert an integer value of any precision to a bigint" (TTerm (IntegerValue -> Integer)
 -> TTerm (IntegerValue -> Integer))
-> TTerm (IntegerValue -> Integer)
-> TTerm (IntegerValue -> Integer)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type
-> TTerm (IntegerValue -> Integer)
-> TTerm (IntegerValue -> Integer)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
integerValueT Type
Types.bigint (TTerm (IntegerValue -> Integer)
 -> TTerm (IntegerValue -> Integer))
-> TTerm (IntegerValue -> Integer)
-> TTerm (IntegerValue -> Integer)
forall a b. (a -> b) -> a -> b
$
  Name
-> Maybe (TTerm Integer)
-> [Field]
-> TTerm (IntegerValue -> Integer)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_IntegerValue Maybe (TTerm Integer)
forall a. Maybe a
Nothing [
    Name
_IntegerValue_bigintName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Any -> Any)
forall x. TTerm (x -> x)
Equality.identity,
    Name
_IntegerValue_int8Name -> TTerm (Int8 -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Int8 -> Integer)
Literals.int8ToBigint,
    Name
_IntegerValue_int16Name -> TTerm (Int16 -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Int16 -> Integer)
Literals.int16ToBigint,
    Name
_IntegerValue_int32Name -> TTerm (Int -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Int -> Integer)
Literals.int32ToBigint,
    Name
_IntegerValue_int64Name -> TTerm (Int64 -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Int64 -> Integer)
Literals.int64ToBigint,
    Name
_IntegerValue_uint8Name -> TTerm (Int16 -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Int16 -> Integer)
Literals.uint8ToBigint,
    Name
_IntegerValue_uint16Name -> TTerm (Int -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Int -> Integer)
Literals.uint16ToBigint,
    Name
_IntegerValue_uint32Name -> TTerm (Int64 -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Int64 -> Integer)
Literals.uint32ToBigint,
    Name
_IntegerValue_uint64Name -> TTerm (Integer -> Integer) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Integer -> Integer)
Literals.uint64ToBigint]

isLambdaDef :: TElement (Term -> Bool)
isLambdaDef :: TElement (Term -> Bool)
isLambdaDef = String -> TTerm (Term -> Bool) -> TElement (Term -> Bool)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"isLambda" (TTerm (Term -> Bool) -> TElement (Term -> Bool))
-> TTerm (Term -> Bool) -> TElement (Term -> Bool)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Term -> Bool) -> TTerm (Term -> Bool)
forall a. String -> TTerm a -> TTerm a
doc String
"Check whether a term is a lambda, possibly nested within let and/or annotation terms" (TTerm (Term -> Bool) -> TTerm (Term -> Bool))
-> TTerm (Term -> Bool) -> TTerm (Term -> Bool)
forall a b. (a -> b) -> a -> b
$
  Type -> Type -> TTerm (Term -> Bool) -> TTerm (Term -> Bool)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
termT Type
Types.boolean (TTerm (Term -> Bool) -> TTerm (Term -> Bool))
-> TTerm (Term -> Bool) -> TTerm (Term -> Bool)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm Bool -> TTerm (Term -> Bool)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"term" (TTerm Bool -> TTerm (Term -> Bool))
-> TTerm Bool -> TTerm (Term -> Bool)
forall a b. (a -> b) -> a -> b
$ (Name -> Maybe (TTerm Bool) -> [Field] -> TTerm (Term -> Bool)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Term (TTerm Bool -> Maybe (TTerm Bool)
forall a. a -> Maybe a
Just TTerm Bool
false) [
      Name
_Term_functionName -> TTerm (Any -> Bool) -> Field
forall a. Name -> TTerm a -> Field
>>: Name -> Maybe (TTerm Bool) -> [Field] -> TTerm (Any -> Bool)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Function (TTerm Bool -> Maybe (TTerm Bool)
forall a. a -> Maybe a
Just TTerm Bool
false) [
        Name
_Function_lambdaName -> TTerm (Any -> Bool) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm Bool -> TTerm (Any -> Bool)
forall a b. TTerm a -> TTerm (b -> a)
constant TTerm Bool
true],
      Name
_Term_letName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm Bool -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"lt" (TElement (Term -> Bool) -> TTerm (Term -> Bool)
forall a. TElement a -> TTerm a
ref TElement (Term -> Bool)
isLambdaDef TTerm (Term -> Bool) -> TTerm Term -> TTerm Bool
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (Name -> Name -> TTerm (Any -> Term)
forall a b. Name -> Name -> TTerm (a -> b)
project Name
_Let Name
_Let_environment TTerm (Any -> Term) -> TTerm Any -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"lt"))])
    TTerm (Term -> Bool) -> TTerm Term -> TTerm Bool
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Term -> Term) -> TTerm (Term -> Term)
forall a. TElement a -> TTerm a
ref TElement (Term -> Term)
fullyStripTermDef TTerm (Term -> Term) -> TTerm Term -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Term
forall a. String -> TTerm a
var String
"term")

-- Rewriting.hs

foldOverTermDef :: TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
foldOverTermDef :: forall x.
TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
foldOverTermDef = String
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
-> TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"foldOverTerm" (TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
 -> TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x))
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
-> TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall a. String -> TTerm a -> TTerm a
doc String
"Fold over a term, traversing its subterms in the specified order" (TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
 -> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x))
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall a b. (a -> b) -> a -> b
$
  [Type]
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall a. [Type] -> TTerm a -> TTerm a
functionN [Name -> Type
TypeVariable Name
_TraversalOrder, Type -> Type -> Type
funT Type
xT (Type -> Type -> Type
funT Type
termT Type
xT), Type
xT, Type
termT, Type
xT] (TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
 -> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x))
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (Any -> Any)
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"order" (TTerm (Any -> Any)
 -> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x))
-> TTerm (Any -> Any)
-> TTerm (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"fld" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"b0" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"term" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ (Name -> Maybe (TTerm Any) -> [Field] -> TTerm (Any -> Any)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_TraversalOrder Maybe (TTerm Any)
forall a. Maybe a
Nothing [
    Name
_TraversalOrder_preName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm a -> TTerm (b -> a)
constant (TTerm (Any -> Term -> Any) -> TTerm (Any -> [Term] -> Any)
forall b a. TTerm (b -> a -> b) -> TTerm (b -> [a] -> b)
Base.fold (TElement
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
-> TTerm
     (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
forall a. TElement a -> TTerm a
ref TElement
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
forall x.
TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
foldOverTermDef TTerm
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
-> TTerm TraversalOrder
-> TTerm ((Any -> Term -> Any) -> Any -> Term -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TraversalOrder
forall a. String -> TTerm a
var String
"order" TTerm ((Any -> Term -> Any) -> Any -> Term -> Any)
-> TTerm (Any -> Term -> Any) -> TTerm (Any -> Term -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any -> Term -> Any)
forall a. String -> TTerm a
var String
"fld")
      TTerm (Any -> [Term] -> Any) -> TTerm Any -> TTerm ([Term] -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (Any -> Any -> Any)
forall a. String -> TTerm a
var String
"fld" TTerm (Any -> Any -> Any) -> TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"b0" TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"term")
      TTerm ([Term] -> Any) -> TTerm [Term] -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Term -> [Term]) -> TTerm (Term -> [Term])
forall a. TElement a -> TTerm a
ref TElement (Term -> [Term])
subtermsDef TTerm (Term -> [Term]) -> TTerm Term -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Term
forall a. String -> TTerm a
var String
"term")),
    Name
_TraversalOrder_postName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm a -> TTerm (b -> a)
constant (String -> TTerm (Any -> Any -> Any)
forall a. String -> TTerm a
var String
"fld"
      TTerm (Any -> Any -> Any) -> TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Any -> Term -> Any) -> TTerm (Any -> [Term] -> Any)
forall b a. TTerm (b -> a -> b) -> TTerm (b -> [a] -> b)
Base.fold (TElement
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
-> TTerm
     (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
forall a. TElement a -> TTerm a
ref TElement
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
forall x.
TElement (TraversalOrder -> (x -> Term -> x) -> x -> Term -> x)
foldOverTermDef TTerm
  (TraversalOrder -> (Any -> Term -> Any) -> Any -> Term -> Any)
-> TTerm TraversalOrder
-> TTerm ((Any -> Term -> Any) -> Any -> Term -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TraversalOrder
forall a. String -> TTerm a
var String
"order" TTerm ((Any -> Term -> Any) -> Any -> Term -> Any)
-> TTerm (Any -> Term -> Any) -> TTerm (Any -> Term -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any -> Term -> Any)
forall a. String -> TTerm a
var String
"fld")
        TTerm (Any -> [Term] -> Any) -> TTerm Any -> TTerm ([Term] -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm Any
forall a. String -> TTerm a
var String
"b0")
        TTerm ([Term] -> Any) -> TTerm [Term] -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Term -> [Term]) -> TTerm (Term -> [Term])
forall a. TElement a -> TTerm a
ref TElement (Term -> [Term])
subtermsDef TTerm (Term -> [Term]) -> TTerm Term -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Term
forall a. String -> TTerm a
var String
"term"))
      TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"term")] TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"order")

foldOverTypeDef :: TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
foldOverTypeDef :: forall x.
TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
foldOverTypeDef = String
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
-> TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"foldOverType" (TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
 -> TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x))
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
-> TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall a. String -> TTerm a -> TTerm a
doc String
"Fold over a type, traversing its subtypes in the specified order" (TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
 -> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x))
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall a b. (a -> b) -> a -> b
$
  [Type]
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall a. [Type] -> TTerm a -> TTerm a
functionN [Name -> Type
TypeVariable Name
_TraversalOrder, Type -> Type -> Type
funT Type
xT (Type -> Type -> Type
funT Type
typeT Type
xT), Type
xT, Type
typeT, Type
xT] (TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
 -> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x))
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (Any -> Any)
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"order" (TTerm (Any -> Any)
 -> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x))
-> TTerm (Any -> Any)
-> TTerm (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"fld" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"b0" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"typ" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ (Name -> Maybe (TTerm Any) -> [Field] -> TTerm (Any -> Any)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_TraversalOrder Maybe (TTerm Any)
forall a. Maybe a
Nothing [
    Name
_TraversalOrder_preName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm a -> TTerm (b -> a)
constant (TTerm (Any -> Type -> Any) -> TTerm (Any -> [Type] -> Any)
forall b a. TTerm (b -> a -> b) -> TTerm (b -> [a] -> b)
Base.fold (TElement
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
-> TTerm
     (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
forall a. TElement a -> TTerm a
ref TElement
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
forall x.
TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
foldOverTypeDef TTerm
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
-> TTerm TraversalOrder
-> TTerm ((Any -> Type -> Any) -> Any -> Type -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TraversalOrder
forall a. String -> TTerm a
var String
"order" TTerm ((Any -> Type -> Any) -> Any -> Type -> Any)
-> TTerm (Any -> Type -> Any) -> TTerm (Any -> Type -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any -> Type -> Any)
forall a. String -> TTerm a
var String
"fld")
      TTerm (Any -> [Type] -> Any) -> TTerm Any -> TTerm ([Type] -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (Any -> Any -> Any)
forall a. String -> TTerm a
var String
"fld" TTerm (Any -> Any -> Any) -> TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"b0" TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"typ")
      TTerm ([Type] -> Any) -> TTerm [Type] -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Type -> [Type]) -> TTerm (Type -> [Type])
forall a. TElement a -> TTerm a
ref TElement (Type -> [Type])
subtypesDef TTerm (Type -> [Type]) -> TTerm Type -> TTerm [Type]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Type
forall a. String -> TTerm a
var String
"typ")),
    Name
_TraversalOrder_postName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm a -> TTerm (b -> a)
constant (String -> TTerm (Any -> Any -> Any)
forall a. String -> TTerm a
var String
"fld"
      TTerm (Any -> Any -> Any) -> TTerm Any -> TTerm (Any -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Any -> Type -> Any) -> TTerm (Any -> [Type] -> Any)
forall b a. TTerm (b -> a -> b) -> TTerm (b -> [a] -> b)
Base.fold (TElement
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
-> TTerm
     (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
forall a. TElement a -> TTerm a
ref TElement
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
forall x.
TElement (TraversalOrder -> (x -> Type -> x) -> x -> Type -> x)
foldOverTypeDef TTerm
  (TraversalOrder -> (Any -> Type -> Any) -> Any -> Type -> Any)
-> TTerm TraversalOrder
-> TTerm ((Any -> Type -> Any) -> Any -> Type -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TraversalOrder
forall a. String -> TTerm a
var String
"order" TTerm ((Any -> Type -> Any) -> Any -> Type -> Any)
-> TTerm (Any -> Type -> Any) -> TTerm (Any -> Type -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any -> Type -> Any)
forall a. String -> TTerm a
var String
"fld")
        TTerm (Any -> [Type] -> Any) -> TTerm Any -> TTerm ([Type] -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm Any
forall a. String -> TTerm a
var String
"b0")
        TTerm ([Type] -> Any) -> TTerm [Type] -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Type -> [Type]) -> TTerm (Type -> [Type])
forall a. TElement a -> TTerm a
ref TElement (Type -> [Type])
subtypesDef TTerm (Type -> [Type]) -> TTerm Type -> TTerm [Type]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Type
forall a. String -> TTerm a
var String
"typ"))
      TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"typ")] TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"order")

freeVariablesInTermDef :: TElement (Term -> S.Set Name)
freeVariablesInTermDef :: TElement (Term -> Set Name)
freeVariablesInTermDef = String -> TTerm (Term -> Set Name) -> TElement (Term -> Set Name)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"freeVariablesInTerm" (TTerm (Term -> Set Name) -> TElement (Term -> Set Name))
-> TTerm (Term -> Set Name) -> TElement (Term -> Set Name)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Term -> Set Name) -> TTerm (Term -> Set Name)
forall a. String -> TTerm a -> TTerm a
doc String
"Find the free variables (i.e. variables not bound by a lambda or let) in a term" (TTerm (Term -> Set Name) -> TTerm (Term -> Set Name))
-> TTerm (Term -> Set Name) -> TTerm (Term -> Set Name)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type -> TTerm (Term -> Set Name) -> TTerm (Term -> Set Name)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
termT (Type -> Type
setT Type
nameT) (TTerm (Term -> Set Name) -> TTerm (Term -> Set Name))
-> TTerm (Term -> Set Name) -> TTerm (Term -> Set Name)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm Any -> TTerm (Term -> Set Name)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"term" (
    (Name -> Maybe (TTerm Any) -> [Field] -> TTerm (Any -> Any)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Term (TTerm Any -> Maybe (TTerm Any)
forall a. a -> Maybe a
Just (TTerm Any -> Maybe (TTerm Any)) -> TTerm Any -> Maybe (TTerm Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"dfltVars") [
      Name
_Term_functionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: Name -> Maybe (TTerm Any) -> [Field] -> TTerm (Any -> Any)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Function (TTerm Any -> Maybe (TTerm Any)
forall a. a -> Maybe a
Just (TTerm Any -> Maybe (TTerm Any)) -> TTerm Any -> Maybe (TTerm Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"dfltVars") [
        Name
_Function_lambdaName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm (Set Name) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"l" (TTerm (Name -> Set Name -> Set Name)
forall a. TTerm (a -> Set a -> Set a)
Sets.remove
          TTerm (Name -> Set Name -> Set Name)
-> TTerm Name -> TTerm (Set Name -> Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Lambda -> Name)
Core.lambdaParameter TTerm (Lambda -> Name) -> TTerm Lambda -> TTerm Name
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Lambda
forall a. String -> TTerm a
var String
"l")
          TTerm (Set Name -> Set Name)
-> TTerm (Set Name) -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Term -> Set Name) -> TTerm (Term -> Set Name)
forall a. TElement a -> TTerm a
ref TElement (Term -> Set Name)
freeVariablesInTermDef TTerm (Term -> Set Name) -> TTerm Term -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Lambda -> Term)
Core.lambdaBody TTerm (Lambda -> Term) -> TTerm Lambda -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Lambda
forall a. String -> TTerm a
var String
"l")))],
--      TODO: restore the following
--      _Term_let>>: lambda "l" (Sets.difference
--        @@ (ref freeVariablesInTermDef @@ (Core.letEnvironment @@ var "l"))
--        @@ (Sets.fromList @@ (Lists.map @@ first @@ (Maps.toList @@ (Core.letBindings @@ var "l"))))),
      Name
_Term_variableName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm (Set Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"v" (TTerm (Any -> Set Any)
forall a. TTerm (a -> Set a)
Sets.singleton TTerm (Any -> Set Any) -> TTerm Any -> TTerm (Set Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"v")] TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"term")
    TTerm Any -> [Field] -> TTerm Any
forall a. TTerm a -> [Field] -> TTerm a
`with` [
      String
"dfltVars"String -> TTerm (Set Any) -> Field
forall a. String -> TTerm a -> Field
>: Type -> TTerm (Set Any) -> TTerm (Set Any)
forall a. Type -> TTerm a -> TTerm a
typed (Type -> Type
setT Type
nameT) (TTerm (Set Any) -> TTerm (Set Any))
-> TTerm (Set Any) -> TTerm (Set Any)
forall a b. (a -> b) -> a -> b
$ TTerm (Set Any -> Term -> Set Any)
-> TTerm (Set Any -> [Term] -> Set Any)
forall b a. TTerm (b -> a -> b) -> TTerm (b -> [a] -> b)
Base.fold (String -> TTerm (Any -> Any) -> TTerm (Set Any -> Term -> Set Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"s" (TTerm (Any -> Any) -> TTerm (Set Any -> Term -> Set Any))
-> TTerm (Any -> Any) -> TTerm (Set Any -> Term -> Set Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Set Name) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm (Set Name) -> TTerm (Any -> Any))
-> TTerm (Set Name) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm (Set Name -> Set Name -> Set Name)
forall a. TTerm (Set a -> Set a -> Set a)
Sets.union TTerm (Set Name -> Set Name -> Set Name)
-> TTerm (Set Name) -> TTerm (Set Name -> Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Set Name)
forall a. String -> TTerm a
var String
"s" TTerm (Set Name -> Set Name)
-> TTerm (Set Name) -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Term -> Set Name) -> TTerm (Term -> Set Name)
forall a. TElement a -> TTerm a
ref TElement (Term -> Set Name)
freeVariablesInTermDef TTerm (Term -> Set Name) -> TTerm Term -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Term
forall a. String -> TTerm a
var String
"t"))
        TTerm (Set Any -> [Term] -> Set Any)
-> TTerm (Set Any) -> TTerm ([Term] -> Set Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm (Set Any)
forall a. TTerm (Set a)
Sets.empty
        TTerm ([Term] -> Set Any) -> TTerm [Term] -> TTerm (Set Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Term -> [Term]) -> TTerm (Term -> [Term])
forall a. TElement a -> TTerm a
ref TElement (Term -> [Term])
subtermsDef TTerm (Term -> [Term]) -> TTerm Term -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Term
forall a. String -> TTerm a
var String
"term")])

freeVariablesInTypeDef :: TElement (Type -> S.Set Name)
freeVariablesInTypeDef :: TElement (Type -> Set Name)
freeVariablesInTypeDef = String -> TTerm (Type -> Set Name) -> TElement (Type -> Set Name)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"freeVariablesInType" (TTerm (Type -> Set Name) -> TElement (Type -> Set Name))
-> TTerm (Type -> Set Name) -> TElement (Type -> Set Name)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Type -> Set Name) -> TTerm (Type -> Set Name)
forall a. String -> TTerm a -> TTerm a
doc String
"Find the free variables (i.e. variables not bound by a lambda or let) in a type" (TTerm (Type -> Set Name) -> TTerm (Type -> Set Name))
-> TTerm (Type -> Set Name) -> TTerm (Type -> Set Name)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type -> TTerm (Type -> Set Name) -> TTerm (Type -> Set Name)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
typeT (Type -> Type
setT Type
nameT) (TTerm (Type -> Set Name) -> TTerm (Type -> Set Name))
-> TTerm (Type -> Set Name) -> TTerm (Type -> Set Name)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm Any -> TTerm (Type -> Set Name)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"typ" (
    (Name -> Maybe (TTerm Any) -> [Field] -> TTerm (Any -> Any)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Type (TTerm Any -> Maybe (TTerm Any)
forall a. a -> Maybe a
Just (TTerm Any -> Maybe (TTerm Any)) -> TTerm Any -> Maybe (TTerm Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"dfltVars") [
      Name
_Type_lambdaName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm (Set Name) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"lt" (TTerm (Name -> Set Name -> Set Name)
forall a. TTerm (a -> Set a -> Set a)
Sets.remove
          TTerm (Name -> Set Name -> Set Name)
-> TTerm Name -> TTerm (Set Name -> Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (LambdaType -> Name)
Core.lambdaTypeParameter TTerm (LambdaType -> Name) -> TTerm LambdaType -> TTerm Name
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm LambdaType
forall a. String -> TTerm a
var String
"lt")
          TTerm (Set Name -> Set Name)
-> TTerm (Set Name) -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Type -> Set Name) -> TTerm (Type -> Set Name)
forall a. TElement a -> TTerm a
ref TElement (Type -> Set Name)
freeVariablesInTypeDef TTerm (Type -> Set Name) -> TTerm Type -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (LambdaType -> Type)
Core.lambdaTypeBody TTerm (LambdaType -> Type) -> TTerm LambdaType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm LambdaType
forall a. String -> TTerm a
var String
"lt"))),
      -- TODO: let-types
      Name
_Type_variableName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm (Set Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"v" (TTerm (Any -> Set Any)
forall a. TTerm (a -> Set a)
Sets.singleton TTerm (Any -> Set Any) -> TTerm Any -> TTerm (Set Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"v")] TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"typ")
    TTerm Any -> [Field] -> TTerm Any
forall a. TTerm a -> [Field] -> TTerm a
`with` [
      String
"dfltVars"String -> TTerm (Set Any) -> Field
forall a. String -> TTerm a -> Field
>: Type -> TTerm (Set Any) -> TTerm (Set Any)
forall a. Type -> TTerm a -> TTerm a
typed (Type -> Type
setT Type
nameT) (TTerm (Set Any) -> TTerm (Set Any))
-> TTerm (Set Any) -> TTerm (Set Any)
forall a b. (a -> b) -> a -> b
$ TTerm (Set Any -> Type -> Set Any)
-> TTerm (Set Any -> [Type] -> Set Any)
forall b a. TTerm (b -> a -> b) -> TTerm (b -> [a] -> b)
Base.fold (String -> TTerm (Any -> Any) -> TTerm (Set Any -> Type -> Set Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"s" (TTerm (Any -> Any) -> TTerm (Set Any -> Type -> Set Any))
-> TTerm (Any -> Any) -> TTerm (Set Any -> Type -> Set Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Set Name) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm (Set Name) -> TTerm (Any -> Any))
-> TTerm (Set Name) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm (Set Name -> Set Name -> Set Name)
forall a. TTerm (Set a -> Set a -> Set a)
Sets.union TTerm (Set Name -> Set Name -> Set Name)
-> TTerm (Set Name) -> TTerm (Set Name -> Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Set Name)
forall a. String -> TTerm a
var String
"s" TTerm (Set Name -> Set Name)
-> TTerm (Set Name) -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Type -> Set Name) -> TTerm (Type -> Set Name)
forall a. TElement a -> TTerm a
ref TElement (Type -> Set Name)
freeVariablesInTypeDef TTerm (Type -> Set Name) -> TTerm Type -> TTerm (Set Name)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Type
forall a. String -> TTerm a
var String
"t"))
        TTerm (Set Any -> [Type] -> Set Any)
-> TTerm (Set Any) -> TTerm ([Type] -> Set Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm (Set Any)
forall a. TTerm (Set a)
Sets.empty
        TTerm ([Type] -> Set Any) -> TTerm [Type] -> TTerm (Set Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TElement (Type -> [Type]) -> TTerm (Type -> [Type])
forall a. TElement a -> TTerm a
ref TElement (Type -> [Type])
subtypesDef TTerm (Type -> [Type]) -> TTerm Type -> TTerm [Type]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Type
forall a. String -> TTerm a
var String
"typ")])

subtermsDef :: TElement (Term -> [Term])
subtermsDef :: TElement (Term -> [Term])
subtermsDef = String -> TTerm (Term -> [Term]) -> TElement (Term -> [Term])
forall a. String -> TTerm a -> TElement a
tier1Definition String
"subterms" (TTerm (Term -> [Term]) -> TElement (Term -> [Term]))
-> TTerm (Term -> [Term]) -> TElement (Term -> [Term])
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Term -> [Term]) -> TTerm (Term -> [Term])
forall a. String -> TTerm a -> TTerm a
doc String
"Find the children of a given term" (TTerm (Term -> [Term]) -> TTerm (Term -> [Term]))
-> TTerm (Term -> [Term]) -> TTerm (Term -> [Term])
forall a b. (a -> b) -> a -> b
$
  Type -> Type -> TTerm (Term -> [Term]) -> TTerm (Term -> [Term])
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
termT (Type -> Type
listT Type
termT) (TTerm (Term -> [Term]) -> TTerm (Term -> [Term]))
-> TTerm (Term -> [Term]) -> TTerm (Term -> [Term])
forall a b. (a -> b) -> a -> b
$
  Name -> Maybe (TTerm [Term]) -> [Field] -> TTerm (Term -> [Term])
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Term Maybe (TTerm [Term])
forall a. Maybe a
Nothing [
    Name
_Term_annotatedName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"at" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (AnnotatedTerm -> Term)
Core.annotatedTermSubject TTerm (AnnotatedTerm -> Term) -> TTerm AnnotatedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm AnnotatedTerm
forall a. String -> TTerm a
var String
"at"],
    Name
_Term_applicationName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"p" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [
      TTerm (Application -> Term)
Core.applicationFunction TTerm (Application -> Term) -> TTerm Application -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Application
forall a. String -> TTerm a
var String
"p",
      TTerm (Application -> Term)
Core.applicationArgument TTerm (Application -> Term) -> TTerm Application -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Application
forall a. String -> TTerm a
var String
"p"],
    Name
_Term_functionName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: Name -> Maybe (TTerm [Any]) -> [Field] -> TTerm (Any -> [Any])
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Function (TTerm [Any] -> Maybe (TTerm [Any])
forall a. a -> Maybe a
Just (TTerm [Any] -> Maybe (TTerm [Any]))
-> TTerm [Any] -> Maybe (TTerm [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list []) [
        Name
_Function_eliminationName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: Name -> Maybe (TTerm [Any]) -> [Field] -> TTerm (Any -> [Any])
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Elimination (TTerm [Any] -> Maybe (TTerm [Any])
forall a. a -> Maybe a
Just (TTerm [Any] -> Maybe (TTerm [Any]))
-> TTerm [Any] -> Maybe (TTerm [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list []) [
            Name
_Elimination_listName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"fld" (TTerm [Any] -> TTerm (Any -> Any))
-> TTerm [Any] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [String -> TTerm Any
forall a. String -> TTerm a
var String
"fld"],
            Name
_Elimination_optionalName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"oc" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [
              TTerm (OptionalCases -> Term)
Core.optionalCasesNothing TTerm (OptionalCases -> Term) -> TTerm OptionalCases -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm OptionalCases
forall a. String -> TTerm a
var String
"oc",
              TTerm (OptionalCases -> Term)
Core.optionalCasesJust TTerm (OptionalCases -> Term) -> TTerm OptionalCases -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm OptionalCases
forall a. String -> TTerm a
var String
"oc"],
            Name
_Elimination_unionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"cs" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm ([Term] -> [Term] -> [Term])
forall a. TTerm ([a] -> [a] -> [a])
Lists.concat2
              TTerm ([Term] -> [Term] -> [Term])
-> TTerm [Term] -> TTerm ([Term] -> [Term])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ ((TTerm [Term]
-> TTerm (Term -> [Term]) -> TTerm (Maybe Term -> [Term])
forall b a. TTerm b -> TTerm (a -> b) -> TTerm (Maybe a -> b)
matchOpt ([TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list []) (String -> TTerm [Any] -> TTerm (Term -> [Term])
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm [Any] -> TTerm (Term -> [Term]))
-> TTerm [Any] -> TTerm (Term -> [Term])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [String -> TTerm Any
forall a. String -> TTerm a
var String
"t"])) TTerm (Maybe Term -> [Term]) -> TTerm (Maybe Term) -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (CaseStatement -> Maybe Term)
Core.caseStatementDefault TTerm (CaseStatement -> Maybe Term)
-> TTerm CaseStatement -> TTerm (Maybe Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm CaseStatement
forall a. String -> TTerm a
var String
"cs"))
              TTerm ([Term] -> [Term]) -> TTerm [Term] -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm ((Field -> Term) -> [Field] -> [Term])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map TTerm ((Field -> Term) -> [Field] -> [Term])
-> TTerm (Field -> Term) -> TTerm ([Field] -> [Term])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm (Field -> Term)
Core.fieldTerm TTerm ([Field] -> [Term]) -> TTerm [Field] -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (CaseStatement -> [Field])
Core.caseStatementCases TTerm (CaseStatement -> [Field])
-> TTerm CaseStatement -> TTerm [Field]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm CaseStatement
forall a. String -> TTerm a
var String
"cs"))],
        Name
_Function_lambdaName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"l" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (Lambda -> Term)
Core.lambdaBody TTerm (Lambda -> Term) -> TTerm Lambda -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Lambda
forall a. String -> TTerm a
var String
"l"]],
    Name
_Term_letName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"lt" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm (Term -> [Term] -> [Term])
forall a. TTerm (a -> [a] -> [a])
Lists.cons
      TTerm (Term -> [Term] -> [Term])
-> TTerm Term -> TTerm ([Term] -> [Term])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Let -> Term)
Core.letEnvironment TTerm (Let -> Term) -> TTerm Let -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Let
forall a. String -> TTerm a
var String
"lt")
      TTerm ([Term] -> [Term]) -> TTerm [Term] -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm ((LetBinding -> Term) -> [LetBinding] -> [Term])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map TTerm ((LetBinding -> Term) -> [LetBinding] -> [Term])
-> TTerm (LetBinding -> Term) -> TTerm ([LetBinding] -> [Term])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm (LetBinding -> Term)
Core.letBindingTerm TTerm ([LetBinding] -> [Term])
-> TTerm [LetBinding] -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Let -> [LetBinding])
Core.letBindings TTerm (Let -> [LetBinding]) -> TTerm Let -> TTerm [LetBinding]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Let
forall a. String -> TTerm a
var String
"lt")),
    Name
_Term_listName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"l" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"l",
    Name
_Term_literalName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any])
forall a b. TTerm a -> TTerm (b -> a)
constant (TTerm [Any] -> TTerm (Any -> [Any]))
-> TTerm [Any] -> TTerm (Any -> [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [],
    Name
_Term_mapName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"m" (TTerm ([[Any]] -> [Any])
forall a. TTerm ([[a]] -> [a])
Lists.concat TTerm ([[Any]] -> [Any]) -> TTerm [[Any]] -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@
      (TTerm (((Any, Any) -> [Any]) -> [(Any, Any)] -> [[Any]])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map TTerm (((Any, Any) -> [Any]) -> [(Any, Any)] -> [[Any]])
-> TTerm ((Any, Any) -> [Any]) -> TTerm ([(Any, Any)] -> [[Any]])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm [Any] -> TTerm ((Any, Any) -> [Any])
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"p" (TTerm [Any] -> TTerm ((Any, Any) -> [Any]))
-> TTerm [Any] -> TTerm ((Any, Any) -> [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [TTerm ((Any, Any) -> Any)
forall a b. TTerm ((a, b) -> a)
first TTerm ((Any, Any) -> Any) -> TTerm (Any, Any) -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any, Any)
forall a. String -> TTerm a
var String
"p", TTerm ((Any, Any) -> Any)
forall a b. TTerm ((a, b) -> b)
second TTerm ((Any, Any) -> Any) -> TTerm (Any, Any) -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any, Any)
forall a. String -> TTerm a
var String
"p"]) TTerm ([(Any, Any)] -> [[Any]])
-> TTerm [(Any, Any)] -> TTerm [[Any]]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Map Any Any -> [(Any, Any)])
forall k v. TTerm (Map k v -> [(k, v)])
Maps.toList TTerm (Map Any Any -> [(Any, Any)])
-> TTerm (Map Any Any) -> TTerm [(Any, Any)]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Map Any Any)
forall a. String -> TTerm a
var String
"m"))),
    Name
_Term_optionalName -> TTerm (Maybe Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any]) -> TTerm (Maybe Any -> [Any])
forall b a. TTerm b -> TTerm (a -> b) -> TTerm (Maybe a -> b)
matchOpt ([TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list []) (String -> TTerm [Any] -> TTerm (Any -> [Any])
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm [Any] -> TTerm (Any -> [Any]))
-> TTerm [Any] -> TTerm (Any -> [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [String -> TTerm Any
forall a. String -> TTerm a
var String
"t"]),
    Name
_Term_productName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"tuple" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"tuple",
    Name
_Term_recordName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"rt" (TTerm ((Field -> Term) -> [Field] -> [Term])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map TTerm ((Field -> Term) -> [Field] -> [Term])
-> TTerm (Field -> Term) -> TTerm ([Field] -> [Term])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm (Field -> Term)
Core.fieldTerm TTerm ([Field] -> [Term]) -> TTerm [Field] -> TTerm [Term]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Record -> [Field])
Core.recordFields TTerm (Record -> [Field]) -> TTerm Record -> TTerm [Field]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Record
forall a. String -> TTerm a
var String
"rt")),
    Name
_Term_setName -> TTerm (Set Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Set Any -> [Any])
forall a. TTerm (Set a -> [a])
Sets.toList,
    Name
_Term_sumName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"st" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (Sum -> Term)
Core.sumTerm TTerm (Sum -> Term) -> TTerm Sum -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Sum
forall a. String -> TTerm a
var String
"st"],
    Name
_Term_typeAbstractionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ta" (TTerm [Type] -> TTerm (Any -> Any))
-> TTerm [Type] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Type] -> TTerm [Type]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (TypeAbstraction -> Type)
Core.typeAbstractionBody TTerm (TypeAbstraction -> Type)
-> TTerm TypeAbstraction -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TypeAbstraction
forall a. String -> TTerm a
var String
"ta"],
    Name
_Term_typeApplicationName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ta" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (TypedTerm -> Term)
Core.typedTermTerm TTerm (TypedTerm -> Term) -> TTerm TypedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TypedTerm
forall a. String -> TTerm a
var String
"ta"],
    Name
_Term_typedName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"tt" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (TypedTerm -> Term)
Core.typedTermTerm TTerm (TypedTerm -> Term) -> TTerm TypedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TypedTerm
forall a. String -> TTerm a
var String
"tt"],
    Name
_Term_unionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ut" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (Field -> Term)
Core.fieldTerm TTerm (Field -> Term) -> TTerm Field -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Injection -> Field)
Core.injectionField TTerm (Injection -> Field) -> TTerm Injection -> TTerm Field
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Injection
forall a. String -> TTerm a
var String
"ut")],
    Name
_Term_variableName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any])
forall a b. TTerm a -> TTerm (b -> a)
constant (TTerm [Any] -> TTerm (Any -> [Any]))
-> TTerm [Any] -> TTerm (Any -> [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [],
    Name
_Term_wrapName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Term] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"n" (TTerm [Term] -> TTerm (Any -> Any))
-> TTerm [Term] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Term] -> TTerm [Term]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (WrappedTerm -> Term)
Core.wrappedTermObject TTerm (WrappedTerm -> Term) -> TTerm WrappedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm WrappedTerm
forall a. String -> TTerm a
var String
"n"]]

subtermsWithAccessorsDef :: TElement (Term -> [(TermAccessor, Term)])
subtermsWithAccessorsDef :: TElement (Term -> [(TermAccessor, Term)])
subtermsWithAccessorsDef = String
-> TTerm (Term -> [(TermAccessor, Term)])
-> TElement (Term -> [(TermAccessor, Term)])
forall a. String -> TTerm a -> TElement a
tier1Definition String
"subtermsWithAccessors" (TTerm (Term -> [(TermAccessor, Term)])
 -> TElement (Term -> [(TermAccessor, Term)]))
-> TTerm (Term -> [(TermAccessor, Term)])
-> TElement (Term -> [(TermAccessor, Term)])
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (Term -> [(TermAccessor, Term)])
-> TTerm (Term -> [(TermAccessor, Term)])
forall a. String -> TTerm a -> TTerm a
doc String
"Find the children of a given term" (TTerm (Term -> [(TermAccessor, Term)])
 -> TTerm (Term -> [(TermAccessor, Term)]))
-> TTerm (Term -> [(TermAccessor, Term)])
-> TTerm (Term -> [(TermAccessor, Term)])
forall a b. (a -> b) -> a -> b
$
  Type
-> Type
-> TTerm (Term -> [(TermAccessor, Term)])
-> TTerm (Term -> [(TermAccessor, Term)])
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
termT (Type -> Type
listT (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
pairT Type
termAccessorT Type
termT) (TTerm (Term -> [(TermAccessor, Term)])
 -> TTerm (Term -> [(TermAccessor, Term)]))
-> TTerm (Term -> [(TermAccessor, Term)])
-> TTerm (Term -> [(TermAccessor, Term)])
forall a b. (a -> b) -> a -> b
$
  Name
-> Maybe (TTerm [(TermAccessor, Term)])
-> [Field]
-> TTerm (Term -> [(TermAccessor, Term)])
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Term Maybe (TTerm [(TermAccessor, Term)])
forall a. Maybe a
Nothing [
    Name
_Term_annotatedName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"at" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Term -> TTerm [(TermAccessor, Term)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorAnnotatedSubject (TTerm Term -> TTerm [(TermAccessor, Term)])
-> TTerm Term -> TTerm [(TermAccessor, Term)]
forall a b. (a -> b) -> a -> b
$ TTerm (AnnotatedTerm -> Term)
Core.annotatedTermSubject TTerm (AnnotatedTerm -> Term) -> TTerm AnnotatedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm AnnotatedTerm
forall a. String -> TTerm a
var String
"at",
    Name
_Term_applicationName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"p" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm (TermAccessor, Term)] -> TTerm [(TermAccessor, Term)]
forall a. [TTerm a] -> TTerm [a]
list [
      TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result TTerm TermAccessor
termAccessorApplicationFunction (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (Application -> Term)
Core.applicationFunction TTerm (Application -> Term) -> TTerm Application -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Application
forall a. String -> TTerm a
var String
"p",
      TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result TTerm TermAccessor
termAccessorApplicationArgument (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (Application -> Term)
Core.applicationArgument TTerm (Application -> Term) -> TTerm Application -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Application
forall a. String -> TTerm a
var String
"p"],
    Name
_Term_functionName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: Name -> Maybe (TTerm [Any]) -> [Field] -> TTerm (Any -> [Any])
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Function (TTerm [Any] -> Maybe (TTerm [Any])
forall a. a -> Maybe a
Just TTerm [Any]
forall {a}. TTerm [a]
none) [
        Name
_Function_eliminationName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: Name -> Maybe (TTerm [Any]) -> [Field] -> TTerm (Any -> [Any])
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Elimination (TTerm [Any] -> Maybe (TTerm [Any])
forall a. a -> Maybe a
Just TTerm [Any]
forall {a}. TTerm [a]
none) [
            Name
_Elimination_listName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Any)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"fld" (TTerm [(TermAccessor, Any)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Any)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Any -> TTerm [(TermAccessor, Any)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorListFold (TTerm Any -> TTerm [(TermAccessor, Any)])
-> TTerm Any -> TTerm [(TermAccessor, Any)]
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"fld",
            Name
_Elimination_optionalName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"oc" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm (TermAccessor, Term)] -> TTerm [(TermAccessor, Term)]
forall a. [TTerm a] -> TTerm [a]
list [
              TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result TTerm TermAccessor
termAccessorOptionalCasesNothing (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (OptionalCases -> Term)
Core.optionalCasesNothing TTerm (OptionalCases -> Term) -> TTerm OptionalCases -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm OptionalCases
forall a. String -> TTerm a
var String
"oc",
              TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result TTerm TermAccessor
termAccessorOptionalCasesJust (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (OptionalCases -> Term)
Core.optionalCasesJust TTerm (OptionalCases -> Term) -> TTerm OptionalCases -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm OptionalCases
forall a. String -> TTerm a
var String
"oc"],
            Name
_Elimination_unionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"cs" (TTerm [Any] -> TTerm (Any -> Any))
-> TTerm [Any] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm ([Any] -> [Any] -> [Any])
forall a. TTerm ([a] -> [a] -> [a])
Lists.concat2
              TTerm ([Any] -> [Any] -> [Any])
-> TTerm [Any] -> TTerm ([Any] -> [Any])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ ((TTerm [Any] -> TTerm (Term -> [Any]) -> TTerm (Maybe Term -> [Any])
forall b a. TTerm b -> TTerm (a -> b) -> TTerm (Maybe a -> b)
matchOpt TTerm [Any]
forall {a}. TTerm [a]
none (String -> TTerm [(TermAccessor, Any)] -> TTerm (Term -> [Any])
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm [(TermAccessor, Any)] -> TTerm (Term -> [Any]))
-> TTerm [(TermAccessor, Any)] -> TTerm (Term -> [Any])
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Any -> TTerm [(TermAccessor, Any)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorUnionCasesDefault (TTerm Any -> TTerm [(TermAccessor, Any)])
-> TTerm Any -> TTerm [(TermAccessor, Any)]
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"t")) TTerm (Maybe Term -> [Any]) -> TTerm (Maybe Term) -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (CaseStatement -> Maybe Term)
Core.caseStatementDefault TTerm (CaseStatement -> Maybe Term)
-> TTerm CaseStatement -> TTerm (Maybe Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm CaseStatement
forall a. String -> TTerm a
var String
"cs"))
              TTerm ([Any] -> [Any]) -> TTerm [Any] -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm ((Field -> Any) -> [Field] -> [Any])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map
                TTerm ((Field -> Any) -> [Field] -> [Any])
-> TTerm (Field -> Any) -> TTerm ([Field] -> [Any])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (TermAccessor, Term) -> TTerm (Field -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"f" (TTerm (TermAccessor, Term) -> TTerm (Field -> Any))
-> TTerm (TermAccessor, Term) -> TTerm (Field -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Name -> TTerm TermAccessor
termAccessorUnionCasesBranch (TTerm Name -> TTerm TermAccessor)
-> TTerm Name -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ TTerm (Field -> Name)
Core.fieldName TTerm (Field -> Name) -> TTerm Field -> TTerm Name
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Field
forall a. String -> TTerm a
var String
"f") (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (Field -> Term)
Core.fieldTerm TTerm (Field -> Term) -> TTerm Field -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Field
forall a. String -> TTerm a
var String
"f")
                TTerm ([Field] -> [Any]) -> TTerm [Field] -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (CaseStatement -> [Field])
Core.caseStatementCases TTerm (CaseStatement -> [Field])
-> TTerm CaseStatement -> TTerm [Field]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm CaseStatement
forall a. String -> TTerm a
var String
"cs"))],
        Name
_Function_lambdaName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"l" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Term -> TTerm [(TermAccessor, Term)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorLambdaBody (TTerm Term -> TTerm [(TermAccessor, Term)])
-> TTerm Term -> TTerm [(TermAccessor, Term)]
forall a b. (a -> b) -> a -> b
$ TTerm (Lambda -> Term)
Core.lambdaBody TTerm (Lambda -> Term) -> TTerm Lambda -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Lambda
forall a. String -> TTerm a
var String
"l"],
    Name
_Term_letName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"lt" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm
  ((TermAccessor, Term)
   -> [(TermAccessor, Term)] -> [(TermAccessor, Term)])
forall a. TTerm (a -> [a] -> [a])
Lists.cons
      TTerm
  ((TermAccessor, Term)
   -> [(TermAccessor, Term)] -> [(TermAccessor, Term)])
-> TTerm (TermAccessor, Term)
-> TTerm ([(TermAccessor, Term)] -> [(TermAccessor, Term)])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result TTerm TermAccessor
termAccessorLetEnvironment (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (Let -> Term)
Core.letEnvironment TTerm (Let -> Term) -> TTerm Let -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Let
forall a. String -> TTerm a
var String
"lt")
      TTerm ([(TermAccessor, Term)] -> [(TermAccessor, Term)])
-> TTerm [(TermAccessor, Term)] -> TTerm [(TermAccessor, Term)]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm
  ((LetBinding -> (TermAccessor, Term))
   -> [LetBinding] -> [(TermAccessor, Term)])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map
        TTerm
  ((LetBinding -> (TermAccessor, Term))
   -> [LetBinding] -> [(TermAccessor, Term)])
-> TTerm (LetBinding -> (TermAccessor, Term))
-> TTerm ([LetBinding] -> [(TermAccessor, Term)])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String
-> TTerm (TermAccessor, Term)
-> TTerm (LetBinding -> (TermAccessor, Term))
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"b" (TTerm (TermAccessor, Term)
 -> TTerm (LetBinding -> (TermAccessor, Term)))
-> TTerm (TermAccessor, Term)
-> TTerm (LetBinding -> (TermAccessor, Term))
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Name -> TTerm TermAccessor
termAccessorLetBinding (TTerm Name -> TTerm TermAccessor)
-> TTerm Name -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ TTerm (LetBinding -> Name)
Core.letBindingName TTerm (LetBinding -> Name) -> TTerm LetBinding -> TTerm Name
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm LetBinding
forall a. String -> TTerm a
var String
"b") (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (LetBinding -> Term)
Core.letBindingTerm TTerm (LetBinding -> Term) -> TTerm LetBinding -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm LetBinding
forall a. String -> TTerm a
var String
"b")
        TTerm ([LetBinding] -> [(TermAccessor, Term)])
-> TTerm [LetBinding] -> TTerm [(TermAccessor, Term)]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Let -> [LetBinding])
Core.letBindings TTerm (Let -> [LetBinding]) -> TTerm Let -> TTerm [LetBinding]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Let
forall a. String -> TTerm a
var String
"lt")),
    Name
_Term_listName -> TTerm ([Any] -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm ((Any -> Any) -> [Any] -> [Any])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map
      -- TODO: use a range of indexes from 0 to len(l)-1, rather than just 0
      TTerm ((Any -> Any) -> [Any] -> [Any])
-> TTerm (Any -> Any) -> TTerm ([Any] -> [Any])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (TermAccessor, Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"e" (TTerm (TermAccessor, Any) -> TTerm (Any -> Any))
-> TTerm (TermAccessor, Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Any -> TTerm (TermAccessor, Any)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Int -> TTerm TermAccessor
termAccessorListElement (TTerm Int -> TTerm TermAccessor)
-> TTerm Int -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ Int -> TTerm Int
int32 Int
0) (TTerm Any -> TTerm (TermAccessor, Any))
-> TTerm Any -> TTerm (TermAccessor, Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"e"),
    Name
_Term_literalName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any])
forall a b. TTerm a -> TTerm (b -> a)
constant TTerm [Any]
forall {a}. TTerm [a]
none,
    Name
_Term_mapName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"m" (TTerm ([[Any]] -> [Any])
forall a. TTerm ([[a]] -> [a])
Lists.concat TTerm ([[Any]] -> [Any]) -> TTerm [[Any]] -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@
      (TTerm (((Any, Any) -> [Any]) -> [(Any, Any)] -> [[Any]])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map
        TTerm (((Any, Any) -> [Any]) -> [(Any, Any)] -> [[Any]])
-> TTerm ((Any, Any) -> [Any]) -> TTerm ([(Any, Any)] -> [[Any]])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String
-> TTerm [(TermAccessor, Any)] -> TTerm ((Any, Any) -> [Any])
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"p" (TTerm [(TermAccessor, Any)] -> TTerm ((Any, Any) -> [Any]))
-> TTerm [(TermAccessor, Any)] -> TTerm ((Any, Any) -> [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm (TermAccessor, Any)] -> TTerm [(TermAccessor, Any)]
forall a. [TTerm a] -> TTerm [a]
list [
          -- TODO: use a range of indexes from 0 to len(l)-1, rather than just 0
          TTerm TermAccessor -> TTerm Any -> TTerm (TermAccessor, Any)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Int -> TTerm TermAccessor
termAccessorMapKey (TTerm Int -> TTerm TermAccessor)
-> TTerm Int -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ Int -> TTerm Int
int32 Int
0) (TTerm Any -> TTerm (TermAccessor, Any))
-> TTerm Any -> TTerm (TermAccessor, Any)
forall a b. (a -> b) -> a -> b
$ TTerm ((Any, Any) -> Any)
forall a b. TTerm ((a, b) -> a)
first TTerm ((Any, Any) -> Any) -> TTerm (Any, Any) -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any, Any)
forall a. String -> TTerm a
var String
"p",
          TTerm TermAccessor -> TTerm Any -> TTerm (TermAccessor, Any)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Int -> TTerm TermAccessor
termAccessorMapValue (TTerm Int -> TTerm TermAccessor)
-> TTerm Int -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ Int -> TTerm Int
int32 Int
0) (TTerm Any -> TTerm (TermAccessor, Any))
-> TTerm Any -> TTerm (TermAccessor, Any)
forall a b. (a -> b) -> a -> b
$ TTerm ((Any, Any) -> Any)
forall a b. TTerm ((a, b) -> b)
second TTerm ((Any, Any) -> Any) -> TTerm (Any, Any) -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Any, Any)
forall a. String -> TTerm a
var String
"p"])
        TTerm ([(Any, Any)] -> [[Any]])
-> TTerm [(Any, Any)] -> TTerm [[Any]]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Map Any Any -> [(Any, Any)])
forall k v. TTerm (Map k v -> [(k, v)])
Maps.toList TTerm (Map Any Any -> [(Any, Any)])
-> TTerm (Map Any Any) -> TTerm [(Any, Any)]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Map Any Any)
forall a. String -> TTerm a
var String
"m"))),
    Name
_Term_optionalName -> TTerm (Maybe Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any]) -> TTerm (Maybe Any -> [Any])
forall b a. TTerm b -> TTerm (a -> b) -> TTerm (Maybe a -> b)
matchOpt TTerm [Any]
forall {a}. TTerm [a]
none (String -> TTerm [(TermAccessor, Any)] -> TTerm (Any -> [Any])
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm [(TermAccessor, Any)] -> TTerm (Any -> [Any]))
-> TTerm [(TermAccessor, Any)] -> TTerm (Any -> [Any])
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Any -> TTerm [(TermAccessor, Any)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorOptionalTerm (TTerm Any -> TTerm [(TermAccessor, Any)])
-> TTerm Any -> TTerm [(TermAccessor, Any)]
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"t"),
    Name
_Term_productName -> TTerm ([Any] -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm ((Any -> Any) -> [Any] -> [Any])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map
      -- TODO: use a range of indexes from 0 to len(l)-1, rather than just 0
      TTerm ((Any -> Any) -> [Any] -> [Any])
-> TTerm (Any -> Any) -> TTerm ([Any] -> [Any])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (TermAccessor, Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"e" (TTerm (TermAccessor, Any) -> TTerm (Any -> Any))
-> TTerm (TermAccessor, Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Any -> TTerm (TermAccessor, Any)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Int -> TTerm TermAccessor
termAccessorProductTerm (TTerm Int -> TTerm TermAccessor)
-> TTerm Int -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ Int -> TTerm Int
int32 Int
0) (TTerm Any -> TTerm (TermAccessor, Any))
-> TTerm Any -> TTerm (TermAccessor, Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"e"),
    Name
_Term_recordName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"rt" (TTerm ((Field -> Any) -> [Field] -> [Any])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map
      TTerm ((Field -> Any) -> [Field] -> [Any])
-> TTerm (Field -> Any) -> TTerm ([Field] -> [Any])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (TermAccessor, Term) -> TTerm (Field -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"f" (TTerm (TermAccessor, Term) -> TTerm (Field -> Any))
-> TTerm (TermAccessor, Term) -> TTerm (Field -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Term -> TTerm (TermAccessor, Term)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Name -> TTerm TermAccessor
termAccessorRecordField (TTerm Name -> TTerm TermAccessor)
-> TTerm Name -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ TTerm (Field -> Name)
Core.fieldName TTerm (Field -> Name) -> TTerm Field -> TTerm Name
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Field
forall a. String -> TTerm a
var String
"f") (TTerm Term -> TTerm (TermAccessor, Term))
-> TTerm Term -> TTerm (TermAccessor, Term)
forall a b. (a -> b) -> a -> b
$ TTerm (Field -> Term)
Core.fieldTerm TTerm (Field -> Term) -> TTerm Field -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Field
forall a. String -> TTerm a
var String
"f")
      TTerm ([Field] -> [Any]) -> TTerm [Field] -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Record -> [Field])
Core.recordFields TTerm (Record -> [Field]) -> TTerm Record -> TTerm [Field]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Record
forall a. String -> TTerm a
var String
"rt")),
    Name
_Term_setName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"s" (TTerm [Any] -> TTerm (Any -> Any))
-> TTerm [Any] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm ((Any -> Any) -> [Any] -> [Any])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map
      -- TODO: use a range of indexes from 0 to len(l)-1, rather than just 0
      TTerm ((Any -> Any) -> [Any] -> [Any])
-> TTerm (Any -> Any) -> TTerm ([Any] -> [Any])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (TermAccessor, Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"e" (TTerm (TermAccessor, Any) -> TTerm (Any -> Any))
-> TTerm (TermAccessor, Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Any -> TTerm (TermAccessor, Any)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result (TTerm Int -> TTerm TermAccessor
termAccessorListElement (TTerm Int -> TTerm TermAccessor)
-> TTerm Int -> TTerm TermAccessor
forall a b. (a -> b) -> a -> b
$ Int -> TTerm Int
int32 Int
0) (TTerm Any -> TTerm (TermAccessor, Any))
-> TTerm Any -> TTerm (TermAccessor, Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"e")
      TTerm ([Any] -> [Any]) -> TTerm [Any] -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Set Any -> [Any])
forall a. TTerm (Set a -> [a])
Sets.toList TTerm (Set Any -> [Any]) -> TTerm (Set Any) -> TTerm [Any]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Set Any)
forall a. String -> TTerm a
var String
"s"),
    Name
_Term_sumName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"st" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
      TTerm TermAccessor -> TTerm Term -> TTerm [(TermAccessor, Term)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorSumTerm (TTerm Term -> TTerm [(TermAccessor, Term)])
-> TTerm Term -> TTerm [(TermAccessor, Term)]
forall a b. (a -> b) -> a -> b
$
      TTerm (Sum -> Term)
Core.sumTerm TTerm (Sum -> Term) -> TTerm Sum -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Sum
forall a. String -> TTerm a
var String
"st",
    Name
_Term_typeAbstractionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Type)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ta" (TTerm [(TermAccessor, Type)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Type)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
      TTerm TermAccessor -> TTerm Type -> TTerm [(TermAccessor, Type)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorTypeAbstractionBody (TTerm Type -> TTerm [(TermAccessor, Type)])
-> TTerm Type -> TTerm [(TermAccessor, Type)]
forall a b. (a -> b) -> a -> b
$
      TTerm (TypeAbstraction -> Type)
Core.typeAbstractionBody TTerm (TypeAbstraction -> Type)
-> TTerm TypeAbstraction -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TypeAbstraction
forall a. String -> TTerm a
var String
"ta",
    Name
_Term_typeApplicationName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ta" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
      TTerm TermAccessor -> TTerm Term -> TTerm [(TermAccessor, Term)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorTypeApplicationTerm (TTerm Term -> TTerm [(TermAccessor, Term)])
-> TTerm Term -> TTerm [(TermAccessor, Term)]
forall a b. (a -> b) -> a -> b
$
      TTerm (TypedTerm -> Term)
Core.typedTermTerm TTerm (TypedTerm -> Term) -> TTerm TypedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TypedTerm
forall a. String -> TTerm a
var String
"ta",
    Name
_Term_typedName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"tt" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
      TTerm TermAccessor -> TTerm Term -> TTerm [(TermAccessor, Term)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorTypedTerm (TTerm Term -> TTerm [(TermAccessor, Term)])
-> TTerm Term -> TTerm [(TermAccessor, Term)]
forall a b. (a -> b) -> a -> b
$
      TTerm (TypedTerm -> Term)
Core.typedTermTerm TTerm (TypedTerm -> Term) -> TTerm TypedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm TypedTerm
forall a. String -> TTerm a
var String
"tt",
    Name
_Term_unionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ut" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
      TTerm TermAccessor -> TTerm Term -> TTerm [(TermAccessor, Term)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorInjectionTerm (TTerm Term -> TTerm [(TermAccessor, Term)])
-> TTerm Term -> TTerm [(TermAccessor, Term)]
forall a b. (a -> b) -> a -> b
$
      TTerm (Field -> Term)
Core.fieldTerm TTerm (Field -> Term) -> TTerm Field -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Injection -> Field)
Core.injectionField TTerm (Injection -> Field) -> TTerm Injection -> TTerm Field
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Injection
forall a. String -> TTerm a
var String
"ut"),
    Name
_Term_variableName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any])
forall a b. TTerm a -> TTerm (b -> a)
constant TTerm [Any]
forall {a}. TTerm [a]
none,
    Name
_Term_wrapName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"n" (TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any))
-> TTerm [(TermAccessor, Term)] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm TermAccessor -> TTerm Term -> TTerm [(TermAccessor, Term)]
forall {a} {b}. TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm TermAccessor
termAccessorWrappedTerm (TTerm Term -> TTerm [(TermAccessor, Term)])
-> TTerm Term -> TTerm [(TermAccessor, Term)]
forall a b. (a -> b) -> a -> b
$ TTerm (WrappedTerm -> Term)
Core.wrappedTermObject TTerm (WrappedTerm -> Term) -> TTerm WrappedTerm -> TTerm Term
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm WrappedTerm
forall a. String -> TTerm a
var String
"n"]
  where
    none :: TTerm [a]
none = [TTerm a] -> TTerm [a]
forall a. [TTerm a] -> TTerm [a]
list []
    single :: TTerm a -> TTerm b -> TTerm [(a, b)]
single TTerm a
accessor TTerm b
term = [TTerm (a, b)] -> TTerm [(a, b)]
forall a. [TTerm a] -> TTerm [a]
list [TTerm a -> TTerm b -> TTerm (a, b)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result TTerm a
accessor TTerm b
term]
    result :: TTerm a -> TTerm b -> TTerm (a, b)
result TTerm a
accessor TTerm b
term = TTerm a -> TTerm b -> TTerm (a, b)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
pair TTerm a
accessor TTerm b
term
    simple :: TTerm b -> TTerm (TermAccessor, b)
simple TTerm b
term = TTerm TermAccessor -> TTerm b -> TTerm (TermAccessor, b)
forall {a} {b}. TTerm a -> TTerm b -> TTerm (a, b)
result TTerm TermAccessor
termAccessorAnnotatedSubject TTerm b
term

subtypesDef :: TElement (Type -> [Type])
subtypesDef :: TElement (Type -> [Type])
subtypesDef = String -> TTerm (Type -> [Type]) -> TElement (Type -> [Type])
forall a. String -> TTerm a -> TElement a
tier1Definition String
"subtypes" (TTerm (Type -> [Type]) -> TElement (Type -> [Type]))
-> TTerm (Type -> [Type]) -> TElement (Type -> [Type])
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Type -> [Type]) -> TTerm (Type -> [Type])
forall a. String -> TTerm a -> TTerm a
doc String
"Find the children of a given type expression" (TTerm (Type -> [Type]) -> TTerm (Type -> [Type]))
-> TTerm (Type -> [Type]) -> TTerm (Type -> [Type])
forall a b. (a -> b) -> a -> b
$
  Type -> Type -> TTerm (Type -> [Type]) -> TTerm (Type -> [Type])
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
typeT (Type -> Type
listT Type
typeT) (TTerm (Type -> [Type]) -> TTerm (Type -> [Type]))
-> TTerm (Type -> [Type]) -> TTerm (Type -> [Type])
forall a b. (a -> b) -> a -> b
$
  Name -> Maybe (TTerm [Type]) -> [Field] -> TTerm (Type -> [Type])
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Type Maybe (TTerm [Type])
forall a. Maybe a
Nothing [
    Name
_Type_annotatedName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"at" (TTerm [Type] -> TTerm (Any -> Any))
-> TTerm [Type] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Type] -> TTerm [Type]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (AnnotatedType -> Type)
Core.annotatedTypeSubject TTerm (AnnotatedType -> Type) -> TTerm AnnotatedType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm AnnotatedType
forall a. String -> TTerm a
var String
"at"],
    Name
_Type_applicationName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"at" (TTerm [Type] -> TTerm (Any -> Any))
-> TTerm [Type] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Type] -> TTerm [Type]
forall a. [TTerm a] -> TTerm [a]
list [
      TTerm (ApplicationType -> Type)
Core.applicationTypeFunction TTerm (ApplicationType -> Type)
-> TTerm ApplicationType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm ApplicationType
forall a. String -> TTerm a
var String
"at",
      TTerm (ApplicationType -> Type)
Core.applicationTypeArgument TTerm (ApplicationType -> Type)
-> TTerm ApplicationType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm ApplicationType
forall a. String -> TTerm a
var String
"at"],
    Name
_Type_functionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ft" (TTerm [Type] -> TTerm (Any -> Any))
-> TTerm [Type] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Type] -> TTerm [Type]
forall a. [TTerm a] -> TTerm [a]
list [
      TTerm (FunctionType -> Type)
Core.functionTypeDomain TTerm (FunctionType -> Type) -> TTerm FunctionType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm FunctionType
forall a. String -> TTerm a
var String
"ft",
      TTerm (FunctionType -> Type)
Core.functionTypeCodomain TTerm (FunctionType -> Type) -> TTerm FunctionType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm FunctionType
forall a. String -> TTerm a
var String
"ft"],
    Name
_Type_lambdaName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"lt" (TTerm [Type] -> TTerm (Any -> Any))
-> TTerm [Type] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Type] -> TTerm [Type]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (LambdaType -> Type)
Core.lambdaTypeBody TTerm (LambdaType -> Type) -> TTerm LambdaType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm LambdaType
forall a. String -> TTerm a
var String
"lt"],
    Name
_Type_listName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"lt" (TTerm [Any] -> TTerm (Any -> Any))
-> TTerm [Any] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [String -> TTerm Any
forall a. String -> TTerm a
var String
"lt"],
    Name
_Type_literalName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any])
forall a b. TTerm a -> TTerm (b -> a)
constant (TTerm [Any] -> TTerm (Any -> [Any]))
-> TTerm [Any] -> TTerm (Any -> [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [],
    Name
_Type_mapName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"mt" (TTerm [Type] -> TTerm (Any -> Any))
-> TTerm [Type] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Type] -> TTerm [Type]
forall a. [TTerm a] -> TTerm [a]
list [
      TTerm (MapType -> Type)
Core.mapTypeKeys TTerm (MapType -> Type) -> TTerm MapType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm MapType
forall a. String -> TTerm a
var String
"mt",
      TTerm (MapType -> Type)
Core.mapTypeValues TTerm (MapType -> Type) -> TTerm MapType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm MapType
forall a. String -> TTerm a
var String
"mt"],
    Name
_Type_optionalName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ot" (TTerm [Any] -> TTerm (Any -> Any))
-> TTerm [Any] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [String -> TTerm Any
forall a. String -> TTerm a
var String
"ot"],
    Name
_Type_productName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"pt" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"pt",
    Name
_Type_recordName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"rt" (TTerm ((FieldType -> Type) -> [FieldType] -> [Type])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map TTerm ((FieldType -> Type) -> [FieldType] -> [Type])
-> TTerm (FieldType -> Type) -> TTerm ([FieldType] -> [Type])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm (FieldType -> Type)
Core.fieldTypeType TTerm ([FieldType] -> [Type]) -> TTerm [FieldType] -> TTerm [Type]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (RowType -> [FieldType])
Core.rowTypeFields TTerm (RowType -> [FieldType])
-> TTerm RowType -> TTerm [FieldType]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm RowType
forall a. String -> TTerm a
var String
"rt")),
    Name
_Type_setName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Any] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"st" (TTerm [Any] -> TTerm (Any -> Any))
-> TTerm [Any] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [String -> TTerm Any
forall a. String -> TTerm a
var String
"st"],
    Name
_Type_sumName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"st" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"st",
    Name
_Type_unionName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"rt" (TTerm ((FieldType -> Type) -> [FieldType] -> [Type])
forall a b. TTerm ((a -> b) -> [a] -> [b])
Lists.map TTerm ((FieldType -> Type) -> [FieldType] -> [Type])
-> TTerm (FieldType -> Type) -> TTerm ([FieldType] -> [Type])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm (FieldType -> Type)
Core.fieldTypeType TTerm ([FieldType] -> [Type]) -> TTerm [FieldType] -> TTerm [Type]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (RowType -> [FieldType])
Core.rowTypeFields TTerm (RowType -> [FieldType])
-> TTerm RowType -> TTerm [FieldType]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm RowType
forall a. String -> TTerm a
var String
"rt")),
    Name
_Type_variableName -> TTerm (Any -> [Any]) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm [Any] -> TTerm (Any -> [Any])
forall a b. TTerm a -> TTerm (b -> a)
constant (TTerm [Any] -> TTerm (Any -> [Any]))
-> TTerm [Any] -> TTerm (Any -> [Any])
forall a b. (a -> b) -> a -> b
$ [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [],
    Name
_Type_wrapName -> TTerm (Any -> Any) -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm [Type] -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"nt" (TTerm [Type] -> TTerm (Any -> Any))
-> TTerm [Type] -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ [TTerm Type] -> TTerm [Type]
forall a. [TTerm a] -> TTerm [a]
list [TTerm (WrappedType -> Type)
Core.wrappedTypeObject TTerm (WrappedType -> Type) -> TTerm WrappedType -> TTerm Type
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm WrappedType
forall a. String -> TTerm a
var String
"nt"]]

unqualifyNameDef :: TElement (QualifiedName -> Name)
unqualifyNameDef :: TElement (QualifiedName -> Name)
unqualifyNameDef = String
-> TTerm (QualifiedName -> Name)
-> TElement (QualifiedName -> Name)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"unqualifyName" (TTerm (QualifiedName -> Name) -> TElement (QualifiedName -> Name))
-> TTerm (QualifiedName -> Name)
-> TElement (QualifiedName -> Name)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (QualifiedName -> Name) -> TTerm (QualifiedName -> Name)
forall a. String -> TTerm a -> TTerm a
doc String
"Convert a qualified name to a dot-separated name" (TTerm (QualifiedName -> Name) -> TTerm (QualifiedName -> Name))
-> TTerm (QualifiedName -> Name) -> TTerm (QualifiedName -> Name)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type
-> TTerm (QualifiedName -> Name)
-> TTerm (QualifiedName -> Name)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
qualifiedNameT Type
nameT (TTerm (QualifiedName -> Name) -> TTerm (QualifiedName -> Name))
-> TTerm (QualifiedName -> Name) -> TTerm (QualifiedName -> Name)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm Any -> TTerm (QualifiedName -> Name)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"qname" (TTerm Any -> TTerm (QualifiedName -> Name))
-> TTerm Any -> TTerm (QualifiedName -> Name)
forall a b. (a -> b) -> a -> b
$ (Name -> TTerm String -> TTerm Any
forall a b. Name -> TTerm a -> TTerm b
wrap Name
_Name (TTerm String -> TTerm Any) -> TTerm String -> TTerm Any
forall a b. (a -> b) -> a -> b
$ String -> TTerm String
forall a. String -> TTerm a
var String
"prefix" TTerm String -> TTerm String -> TTerm String
++ (Name -> Name -> TTerm (Any -> String)
forall a b. Name -> Name -> TTerm (a -> b)
project Name
_QualifiedName Name
_QualifiedName_local TTerm (Any -> String) -> TTerm Any -> TTerm String
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"qname"))
    TTerm Any -> [Field] -> TTerm Any
forall a. TTerm a -> [Field] -> TTerm a
`with` [
      String
"prefix"String -> TTerm String -> Field
forall a. String -> TTerm a -> Field
>: TTerm String
-> TTerm (Any -> String) -> TTerm (Maybe Any -> String)
forall b a. TTerm b -> TTerm (a -> b) -> TTerm (Maybe a -> b)
matchOpt (String -> TTerm String
string String
"") (String -> TTerm String -> TTerm (Any -> String)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"n" (TTerm String -> TTerm (Any -> String))
-> TTerm String -> TTerm (Any -> String)
forall a b. (a -> b) -> a -> b
$ (Name -> TTerm (Any -> String)
forall a b. Name -> TTerm (a -> b)
unwrap Name
_Namespace TTerm (Any -> String) -> TTerm Any -> TTerm String
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"n") TTerm String -> TTerm String -> TTerm String
++ String -> TTerm String
string String
".")
        TTerm (Maybe Any -> String) -> TTerm (Maybe Any) -> TTerm String
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (Name -> Name -> TTerm (Any -> Maybe Any)
forall a b. Name -> Name -> TTerm (a -> b)
project Name
_QualifiedName Name
_QualifiedName_namespace TTerm (Any -> Maybe Any) -> TTerm Any -> TTerm (Maybe Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"qname")]

-- Flows.hs

emptyTraceDef :: TElement Trace
emptyTraceDef :: TElement Trace
emptyTraceDef = String -> TTerm Trace -> TElement Trace
forall a. String -> TTerm a -> TElement a
tier1Definition String
"emptyTrace" (TTerm Trace -> TElement Trace) -> TTerm Trace -> TElement Trace
forall a b. (a -> b) -> a -> b
$
  Name -> [Field] -> TTerm Trace
forall a. Name -> [Field] -> TTerm a
record Name
_Trace [
    Name
_Trace_stackName -> TTerm [Any] -> Field
forall a. Name -> TTerm a -> Field
>>: [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [],
    Name
_Trace_messagesName -> TTerm [Any] -> Field
forall a. Name -> TTerm a -> Field
>>: [TTerm Any] -> TTerm [Any]
forall a. [TTerm a] -> TTerm [a]
list [],
    Name
_Trace_otherName -> TTerm (Map Any Any) -> Field
forall a. Name -> TTerm a -> Field
>>: TTerm (Map Any Any)
forall k v. TTerm (Map k v)
Maps.empty]

flowSucceedsDef :: TElement (Flow s a -> Bool)
flowSucceedsDef :: forall s a. TElement (Flow s a -> Bool)
flowSucceedsDef = String -> TTerm (Flow s a -> Bool) -> TElement (Flow s a -> Bool)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"flowSucceeds" (TTerm (Flow s a -> Bool) -> TElement (Flow s a -> Bool))
-> TTerm (Flow s a -> Bool) -> TElement (Flow s a -> Bool)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Flow s a -> Bool) -> TTerm (Flow s a -> Bool)
forall a. String -> TTerm a -> TTerm a
doc String
"Check whether a flow succeeds" (TTerm (Flow s a -> Bool) -> TTerm (Flow s a -> Bool))
-> TTerm (Flow s a -> Bool) -> TTerm (Flow s a -> Bool)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type -> TTerm (Flow s a -> Bool) -> TTerm (Flow s a -> Bool)
forall a. Type -> Type -> TTerm a -> TTerm a
function (String -> Type
Types.var String
"s") (Type -> Type -> Type
Types.function Type
flowSAT Type
Types.boolean) (TTerm (Flow s a -> Bool) -> TTerm (Flow s a -> Bool))
-> TTerm (Flow s a -> Bool) -> TTerm (Flow s a -> Bool)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Any -> Any) -> TTerm (Flow s a -> Bool)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"cx" (TTerm (Any -> Any) -> TTerm (Flow s a -> Bool))
-> TTerm (Any -> Any) -> TTerm (Flow s a -> Bool)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Bool -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"f" (TTerm Bool -> TTerm (Any -> Any))
-> TTerm Bool -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
    TTerm (Maybe Any -> Bool)
forall a. TTerm (Maybe a -> Bool)
Optionals.isJust TTerm (Maybe Any -> Bool) -> TTerm (Maybe Any) -> TTerm Bool
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (FlowState Any Any -> Maybe Any)
forall s x. TTerm (FlowState s x -> Maybe x)
Flows.flowStateValue TTerm (FlowState Any Any -> Maybe Any)
-> TTerm (FlowState Any Any) -> TTerm (Maybe Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
forall s x. TTerm (Flow s x -> s -> Trace -> FlowState s x)
Flows.unFlow TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
-> TTerm (Flow Any Any)
-> TTerm (Any -> Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Flow Any Any)
forall a. String -> TTerm a
var String
"f" TTerm (Any -> Trace -> FlowState Any Any)
-> TTerm Any -> TTerm (Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"cx" TTerm (Trace -> FlowState Any Any)
-> TTerm Trace -> TTerm (FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TElement Trace -> TTerm Trace
forall a. TElement a -> TTerm a
ref TElement Trace
emptyTraceDef))

fromFlowDef :: TElement (a -> s -> Flow s a -> a)
fromFlowDef :: forall a s. TElement (a -> s -> Flow s a -> a)
fromFlowDef = String
-> TTerm (a -> s -> Flow s a -> a)
-> TElement (a -> s -> Flow s a -> a)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"fromFlow" (TTerm (a -> s -> Flow s a -> a)
 -> TElement (a -> s -> Flow s a -> a))
-> TTerm (a -> s -> Flow s a -> a)
-> TElement (a -> s -> Flow s a -> a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (a -> s -> Flow s a -> a)
-> TTerm (a -> s -> Flow s a -> a)
forall a. String -> TTerm a -> TTerm a
doc String
"Get the value of a flow, or a default value if the flow fails" (TTerm (a -> s -> Flow s a -> a)
 -> TTerm (a -> s -> Flow s a -> a))
-> TTerm (a -> s -> Flow s a -> a)
-> TTerm (a -> s -> Flow s a -> a)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type
-> TTerm (a -> s -> Flow s a -> a)
-> TTerm (a -> s -> Flow s a -> a)
forall a. Type -> Type -> TTerm a -> TTerm a
function (String -> Type
Types.var String
"a") (Type -> Type -> Type
Types.function (String -> Type
Types.var String
"s") (Type -> Type -> Type
Types.function Type
flowSAT (String -> Type
Types.var String
"a"))) (TTerm (a -> s -> Flow s a -> a)
 -> TTerm (a -> s -> Flow s a -> a))
-> TTerm (a -> s -> Flow s a -> a)
-> TTerm (a -> s -> Flow s a -> a)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Any -> Any) -> TTerm (a -> s -> Flow s a -> a)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"def" (TTerm (Any -> Any) -> TTerm (a -> s -> Flow s a -> a))
-> TTerm (Any -> Any) -> TTerm (a -> s -> Flow s a -> a)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"cx" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"f" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
      TTerm Any -> TTerm (Any -> Any) -> TTerm (Maybe Any -> Any)
forall b a. TTerm b -> TTerm (a -> b) -> TTerm (Maybe a -> b)
matchOpt (String -> TTerm Any
forall a. String -> TTerm a
var String
"def") (String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"x" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any
forall a. String -> TTerm a
var String
"x")
        TTerm (Maybe Any -> Any) -> TTerm (Maybe Any) -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (FlowState Any Any -> Maybe Any)
forall s x. TTerm (FlowState s x -> Maybe x)
Flows.flowStateValue TTerm (FlowState Any Any -> Maybe Any)
-> TTerm (FlowState Any Any) -> TTerm (Maybe Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
forall s x. TTerm (Flow s x -> s -> Trace -> FlowState s x)
Flows.unFlow TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
-> TTerm (Flow Any Any)
-> TTerm (Any -> Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Flow Any Any)
forall a. String -> TTerm a
var String
"f" TTerm (Any -> Trace -> FlowState Any Any)
-> TTerm Any -> TTerm (Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"cx" TTerm (Trace -> FlowState Any Any)
-> TTerm Trace -> TTerm (FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TElement Trace -> TTerm Trace
forall a. TElement a -> TTerm a
ref TElement Trace
emptyTraceDef))

mutateTraceDef :: TElement ((Trace -> Either_ String Trace) -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
mutateTraceDef :: forall s a.
TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
mutateTraceDef = String
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
-> TElement
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"mutateTrace" (TTerm
   ((Trace -> Either_ String Trace)
    -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
 -> TElement
      ((Trace -> Either_ String Trace)
       -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a))
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
-> TElement
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
    [Type]
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
forall a. [Type] -> TTerm a -> TTerm a
functionN [
      Type -> Type -> Type
Types.function Type
traceT (Type -> Type -> Type
eitherT Type
Types.string Type
traceT),
      [Type] -> Type
Types.functionN [Type
traceT, Type
traceT, Type
traceT],
      Type
flowSAT,
      Type
flowSAT] (TTerm
   ((Trace -> Either_ String Trace)
    -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
 -> TTerm
      ((Trace -> Either_ String Trace)
       -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a))
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
    String
-> TTerm (Any -> Any)
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"mutate" (TTerm (Any -> Any)
 -> TTerm
      ((Trace -> Either_ String Trace)
       -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a))
-> TTerm (Any -> Any)
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"restore" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"f" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ Name -> TTerm (Any -> Any) -> TTerm Any
forall a b. Name -> TTerm a -> TTerm b
wrap Name
_Flow (
      String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"s0" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t0" (
        ((Name -> Maybe (TTerm Any) -> [Field] -> TTerm (Any -> Any)
forall b u. Name -> Maybe (TTerm b) -> [Field] -> TTerm (u -> b)
match Name
_Either Maybe (TTerm Any)
forall a. Maybe a
Nothing [
            Name
_Either_leftName -> TTerm Any -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm Any
forall a. String -> TTerm a
var String
"forLeft",
            Name
_Either_rightName -> TTerm Any -> Field
forall a. Name -> TTerm a -> Field
>>: String -> TTerm Any
forall a. String -> TTerm a
var String
"forRight"])
          TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (String -> TTerm (Any -> Any)
forall a. String -> TTerm a
var String
"mutate" TTerm (Any -> Any) -> TTerm Any -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"t0"))
        TTerm Any -> [Field] -> TTerm Any
forall a. TTerm a -> [Field] -> TTerm a
`with` [
          String
"forLeft"String -> TTerm (Any -> Any) -> Field
forall a. String -> TTerm a -> Field
>:
            String -> TTerm (FlowState Any Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"msg" (TTerm (FlowState Any Any) -> TTerm (Any -> Any))
-> TTerm (FlowState Any Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm (Maybe Any)
-> TTerm Any -> TTerm Trace -> TTerm (FlowState Any Any)
forall x s.
TTerm (Maybe x) -> TTerm s -> TTerm Trace -> TTerm (FlowState s x)
Flows.flowState TTerm (Maybe Any)
forall a. TTerm a
nothing (String -> TTerm Any
forall a. String -> TTerm a
var String
"s0") (TElement (String -> Trace -> Trace)
-> TTerm (String -> Trace -> Trace)
forall a. TElement a -> TTerm a
ref TElement (String -> Trace -> Trace)
pushErrorDef TTerm (String -> Trace -> Trace)
-> TTerm String -> TTerm (Trace -> Trace)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm String
forall a. String -> TTerm a
var String
"msg" TTerm (Trace -> Trace) -> TTerm Trace -> TTerm Trace
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t0"),
          -- retain the updated state, but reset the trace after execution
          String
"forRight"String -> TTerm (Any -> Any) -> Field
forall a. String -> TTerm a -> Field
>:
            Type -> Type -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
traceT (Type -> Type -> Type
flowStateT (String -> Type
Types.var String
"s") (String -> Type
Types.var String
"s")) (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
            String -> TTerm (FlowState Any Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t1" ((TTerm (Maybe Any)
-> TTerm Any -> TTerm Trace -> TTerm (FlowState Any Any)
forall x s.
TTerm (Maybe x) -> TTerm s -> TTerm Trace -> TTerm (FlowState s x)
Flows.flowState
                (TTerm (FlowState Any Any -> Maybe Any)
forall s x. TTerm (FlowState s x -> Maybe x)
Flows.flowStateValue TTerm (FlowState Any Any -> Maybe Any)
-> TTerm (FlowState Any Any) -> TTerm (Maybe Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f2")
                (TTerm (FlowState Any Any -> Any)
forall s x. TTerm (FlowState s x -> s)
Flows.flowStateState TTerm (FlowState Any Any -> Any)
-> TTerm (FlowState Any Any) -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f2")
                (String -> TTerm (Any -> Trace -> Trace)
forall a. String -> TTerm a
var String
"restore" TTerm (Any -> Trace -> Trace)
-> TTerm Any -> TTerm (Trace -> Trace)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"t0" TTerm (Trace -> Trace) -> TTerm Trace -> TTerm Trace
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (FlowState Any Any -> Trace)
forall s x. TTerm (FlowState s x -> Trace)
Flows.flowStateTrace TTerm (FlowState Any Any -> Trace)
-> TTerm (FlowState Any Any) -> TTerm Trace
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f2")))
              TTerm (FlowState Any Any) -> [Field] -> TTerm (FlowState Any Any)
forall a. TTerm a -> [Field] -> TTerm a
`with` [
                 -- execute the internal flow after augmenting the trace
                 String
"f2"String -> TTerm (FlowState Any Any) -> Field
forall a. String -> TTerm a -> Field
>: TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
forall s x. TTerm (Flow s x -> s -> Trace -> FlowState s x)
Flows.unFlow TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
-> TTerm (Flow Any Any)
-> TTerm (Any -> Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Flow Any Any)
forall a. String -> TTerm a
var String
"f" TTerm (Any -> Trace -> FlowState Any Any)
-> TTerm Any -> TTerm (Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"s0" TTerm (Trace -> FlowState Any Any)
-> TTerm Trace -> TTerm (FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t1"
              ])]))
  where
    eitherT :: Type -> Type -> Type
eitherT Type
l Type
r = [Type] -> Type
Types.applyN [Name -> Type
TypeVariable Name
_Either, Type
l, Type
r]

pushErrorDef :: TElement (String -> Trace -> Trace)
pushErrorDef :: TElement (String -> Trace -> Trace)
pushErrorDef = String
-> TTerm (String -> Trace -> Trace)
-> TElement (String -> Trace -> Trace)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"pushError" (TTerm (String -> Trace -> Trace)
 -> TElement (String -> Trace -> Trace))
-> TTerm (String -> Trace -> Trace)
-> TElement (String -> Trace -> Trace)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (String -> Trace -> Trace)
-> TTerm (String -> Trace -> Trace)
forall a. String -> TTerm a -> TTerm a
doc String
"Push an error message" (TTerm (String -> Trace -> Trace)
 -> TTerm (String -> Trace -> Trace))
-> TTerm (String -> Trace -> Trace)
-> TTerm (String -> Trace -> Trace)
forall a b. (a -> b) -> a -> b
$
  [Type]
-> TTerm (String -> Trace -> Trace)
-> TTerm (String -> Trace -> Trace)
forall a. [Type] -> TTerm a -> TTerm a
functionN [Type
Types.string, Type
traceT, Type
traceT] (TTerm (String -> Trace -> Trace)
 -> TTerm (String -> Trace -> Trace))
-> TTerm (String -> Trace -> Trace)
-> TTerm (String -> Trace -> Trace)
forall a b. (a -> b) -> a -> b
$
  String -> TTerm (Any -> Any) -> TTerm (String -> Trace -> Trace)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"msg" (TTerm (Any -> Any) -> TTerm (String -> Trace -> Trace))
-> TTerm (Any -> Any) -> TTerm (String -> Trace -> Trace)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Trace -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm Trace -> TTerm (Any -> Any))
-> TTerm Trace -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ ((TTerm [String]
-> TTerm [String] -> TTerm (Map String Term) -> TTerm Trace
Flows.trace
      (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t")
      (TTerm (String -> [String] -> [String])
forall a. TTerm (a -> [a] -> [a])
Lists.cons TTerm (String -> [String] -> [String])
-> TTerm String -> TTerm ([String] -> [String])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm String
forall a. String -> TTerm a
var String
"errorMsg" TTerm ([String] -> [String]) -> TTerm [String] -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Trace -> [String])
Flows.traceMessages TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t"))
      (TTerm (Trace -> Map String Term)
Flows.traceOther TTerm (Trace -> Map String Term)
-> TTerm Trace -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t"))
    TTerm Trace -> [Field] -> TTerm Trace
forall a. TTerm a -> [Field] -> TTerm a
`with` [
      String
"errorMsg"String -> TTerm String -> Field
forall a. String -> TTerm a -> Field
>: [TTerm String] -> TTerm String
Strings.concat [TTerm String
"Error: ", String -> TTerm String
forall a. String -> TTerm a
var String
"msg", TTerm String
" (", (TTerm (String -> [String] -> String)
Strings.intercalate TTerm (String -> [String] -> String)
-> TTerm String -> TTerm ([String] -> String)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TTerm String
" > " TTerm ([String] -> String) -> TTerm [String] -> TTerm String
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm ([String] -> [String])
forall a. TTerm ([a] -> [a])
Lists.reverse TTerm ([String] -> [String]) -> TTerm [String] -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t"))), TTerm String
")"]])

warnDef :: TElement (String -> Flow s a -> Flow s a)
warnDef :: forall s a. TElement (String -> Flow s a -> Flow s a)
warnDef = String
-> TTerm (String -> Flow s a -> Flow s a)
-> TElement (String -> Flow s a -> Flow s a)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"warn" (TTerm (String -> Flow s a -> Flow s a)
 -> TElement (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TElement (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a. String -> TTerm a -> TTerm a
doc String
"Continue the current flow after adding a warning message" (TTerm (String -> Flow s a -> Flow s a)
 -> TTerm (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  [Type]
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a. [Type] -> TTerm a -> TTerm a
functionN [Type
Types.string, Type
flowSAT, Type
flowSAT] (TTerm (String -> Flow s a -> Flow s a)
 -> TTerm (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (Any -> Any) -> TTerm (String -> Flow s a -> Flow s a)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"msg" (TTerm (Any -> Any) -> TTerm (String -> Flow s a -> Flow s a))
-> TTerm (Any -> Any) -> TTerm (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"b" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ Name -> TTerm (Any -> Any) -> TTerm Any
forall a b. Name -> TTerm a -> TTerm b
wrap Name
_Flow (TTerm (Any -> Any) -> TTerm Any)
-> TTerm (Any -> Any) -> TTerm Any
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"s0" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (FlowState Any Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t0" (
    (TTerm (Maybe Any)
-> TTerm Any -> TTerm Trace -> TTerm (FlowState Any Any)
forall x s.
TTerm (Maybe x) -> TTerm s -> TTerm Trace -> TTerm (FlowState s x)
Flows.flowState
      (TTerm (FlowState Any Any -> Maybe Any)
forall s x. TTerm (FlowState s x -> Maybe x)
Flows.flowStateValue TTerm (FlowState Any Any -> Maybe Any)
-> TTerm (FlowState Any Any) -> TTerm (Maybe Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f1")
      (TTerm (FlowState Any Any -> Any)
forall s x. TTerm (FlowState s x -> s)
Flows.flowStateState TTerm (FlowState Any Any -> Any)
-> TTerm (FlowState Any Any) -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f1")
      (String -> TTerm (Trace -> Trace)
forall a. String -> TTerm a
var String
"addMessage" TTerm (Trace -> Trace) -> TTerm Trace -> TTerm Trace
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (FlowState Any Any -> Trace)
forall s x. TTerm (FlowState s x -> Trace)
Flows.flowStateTrace TTerm (FlowState Any Any -> Trace)
-> TTerm (FlowState Any Any) -> TTerm Trace
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f1")))
    TTerm (FlowState Any Any) -> [Field] -> TTerm (FlowState Any Any)
forall a. TTerm a -> [Field] -> TTerm a
`with` [
      String
"f1"String -> TTerm (FlowState Any Any) -> Field
forall a. String -> TTerm a -> Field
>: TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
forall s x. TTerm (Flow s x -> s -> Trace -> FlowState s x)
Flows.unFlow TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
-> TTerm (Flow Any Any)
-> TTerm (Any -> Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Flow Any Any)
forall a. String -> TTerm a
var String
"b" TTerm (Any -> Trace -> FlowState Any Any)
-> TTerm Any -> TTerm (Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"s0" TTerm (Trace -> FlowState Any Any)
-> TTerm Trace -> TTerm (FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t0",
      String
"addMessage"String -> TTerm (Any -> Any) -> Field
forall a. String -> TTerm a -> Field
>: String -> TTerm Trace -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm Trace -> TTerm (Any -> Any))
-> TTerm Trace -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm [String]
-> TTerm [String] -> TTerm (Map String Term) -> TTerm Trace
Flows.trace
        (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t")
        (TTerm (String -> [String] -> [String])
forall a. TTerm (a -> [a] -> [a])
Lists.cons TTerm (String -> [String] -> [String])
-> TTerm String -> TTerm ([String] -> [String])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm String
"Warning: " TTerm String -> TTerm String -> TTerm String
++ String -> TTerm String
forall a. String -> TTerm a
var String
"msg") TTerm ([String] -> [String]) -> TTerm [String] -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Trace -> [String])
Flows.traceMessages TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t"))
        (TTerm (Trace -> Map String Term)
Flows.traceOther TTerm (Trace -> Map String Term)
-> TTerm Trace -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t")])

withFlagDef :: TElement (String -> Flow s a -> Flow s a)
withFlagDef :: forall s a. TElement (String -> Flow s a -> Flow s a)
withFlagDef = String
-> TTerm (String -> Flow s a -> Flow s a)
-> TElement (String -> Flow s a -> Flow s a)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"withFlag" (TTerm (String -> Flow s a -> Flow s a)
 -> TElement (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TElement (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a. String -> TTerm a -> TTerm a
doc String
"Continue the current flow after setting a flag" (TTerm (String -> Flow s a -> Flow s a)
 -> TTerm (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a. Type -> Type -> TTerm a -> TTerm a
function Type
nameT (Type -> Type -> Type
Types.function Type
flowSAT Type
flowSAT) (TTerm (String -> Flow s a -> Flow s a)
 -> TTerm (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (Flow Any Any -> Flow Any Any)
-> TTerm (String -> Flow s a -> Flow s a)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"flag" ((TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
forall a. TElement a -> TTerm a
ref TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
forall s a.
TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
mutateTraceDef TTerm
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
-> TTerm (Trace -> Either_ String Trace)
-> TTerm
     ((Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Trace -> Either_ String Trace)
forall a. String -> TTerm a
var String
"mutate" TTerm ((Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
-> TTerm (Trace -> Trace -> Trace)
-> TTerm (Flow Any Any -> Flow Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Trace -> Trace -> Trace)
forall a. String -> TTerm a
var String
"restore")
  TTerm (Flow Any Any -> Flow Any Any)
-> [Field] -> TTerm (Flow Any Any -> Flow Any Any)
forall a. TTerm a -> [Field] -> TTerm a
`with` [
    String
"mutate"String -> TTerm (Any -> Any) -> Field
forall a. String -> TTerm a -> Field
>: String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ Name -> Name -> TTerm Trace -> TTerm Any
forall a b. Name -> Name -> TTerm a -> TTerm b
inject Name
_Either Name
_Either_right (TTerm Trace -> TTerm Any) -> TTerm Trace -> TTerm Any
forall a b. (a -> b) -> a -> b
$ (TTerm [String]
-> TTerm [String] -> TTerm (Map String Term) -> TTerm Trace
Flows.trace
      (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t")
      (TTerm (Trace -> [String])
Flows.traceMessages TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t")
      (TTerm (String -> Term -> Map String Term -> Map String Term)
forall k v. TTerm (k -> v -> Map k v -> Map k v)
Maps.insert TTerm (String -> Term -> Map String Term -> Map String Term)
-> TTerm String
-> TTerm (Term -> Map String Term -> Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm String
forall a. String -> TTerm a
var String
"flag" TTerm (Term -> Map String Term -> Map String Term)
-> TTerm Term -> TTerm (Map String Term -> Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (Name -> Name -> TTerm Any -> TTerm Term
forall a b. Name -> Name -> TTerm a -> TTerm b
inject Name
_Term Name
_Term_literal (TTerm Any -> TTerm Term) -> TTerm Any -> TTerm Term
forall a b. (a -> b) -> a -> b
$ Name -> Name -> TTerm Bool -> TTerm Any
forall a b. Name -> Name -> TTerm a -> TTerm b
inject Name
_Literal Name
_Literal_boolean (TTerm Bool -> TTerm Any) -> TTerm Bool -> TTerm Any
forall a b. (a -> b) -> a -> b
$ Bool -> TTerm Bool
boolean Bool
True) TTerm (Map String Term -> Map String Term)
-> TTerm (Map String Term) -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Trace -> Map String Term)
Flows.traceOther TTerm (Trace -> Map String Term)
-> TTerm Trace -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t"))),
    String
"restore"String -> TTerm (Any -> Any) -> Field
forall a. String -> TTerm a -> Field
>: String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"ignored" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Trace -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t1" (TTerm Trace -> TTerm (Any -> Any))
-> TTerm Trace -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm [String]
-> TTerm [String] -> TTerm (Map String Term) -> TTerm Trace
Flows.trace
      (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t1")
      (TTerm (Trace -> [String])
Flows.traceMessages TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t1")
      (TTerm (String -> Map String Term -> Map String Term)
forall k v. TTerm (k -> Map k v -> Map k v)
Maps.remove TTerm (String -> Map String Term -> Map String Term)
-> TTerm String -> TTerm (Map String Term -> Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm String
forall a. String -> TTerm a
var String
"flag" TTerm (Map String Term -> Map String Term)
-> TTerm (Map String Term) -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Trace -> Map String Term)
Flows.traceOther TTerm (Trace -> Map String Term)
-> TTerm Trace -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t1"))])

withStateDef :: TElement (s1 -> Flow s1 a -> Flow s2 a)
withStateDef :: forall s1 a s2. TElement (s1 -> Flow s1 a -> Flow s2 a)
withStateDef = String
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
-> TElement (s1 -> Flow s1 a -> Flow s2 a)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"withState" (TTerm (s1 -> Flow s1 a -> Flow s2 a)
 -> TElement (s1 -> Flow s1 a -> Flow s2 a))
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
-> TElement (s1 -> Flow s1 a -> Flow s2 a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
forall a. String -> TTerm a -> TTerm a
doc String
"Continue a flow using a given state" (TTerm (s1 -> Flow s1 a -> Flow s2 a)
 -> TTerm (s1 -> Flow s1 a -> Flow s2 a))
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
forall a b. (a -> b) -> a -> b
$
  Type
-> Type
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
forall a. Type -> Type -> TTerm a -> TTerm a
function (String -> Type
Types.var String
"s1") (Type -> Type -> Type
Types.function Type
flowS1AT Type
flowS2AT) (TTerm (s1 -> Flow s1 a -> Flow s2 a)
 -> TTerm (s1 -> Flow s1 a -> Flow s2 a))
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
-> TTerm (s1 -> Flow s1 a -> Flow s2 a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (Any -> Any) -> TTerm (s1 -> Flow s1 a -> Flow s2 a)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"cx0" (TTerm (Any -> Any) -> TTerm (s1 -> Flow s1 a -> Flow s2 a))
-> TTerm (Any -> Any) -> TTerm (s1 -> Flow s1 a -> Flow s2 a)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"f" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$
    Name -> TTerm (Any -> Any) -> TTerm Any
forall a b. Name -> TTerm a -> TTerm b
wrap Name
_Flow (TTerm (Any -> Any) -> TTerm Any)
-> TTerm (Any -> Any) -> TTerm Any
forall a b. (a -> b) -> a -> b
$ String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"cx1" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm (FlowState Any Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t1" (
      (TTerm (Maybe Any)
-> TTerm Any -> TTerm Trace -> TTerm (FlowState Any Any)
forall x s.
TTerm (Maybe x) -> TTerm s -> TTerm Trace -> TTerm (FlowState s x)
Flows.flowState (TTerm (FlowState Any Any -> Maybe Any)
forall s x. TTerm (FlowState s x -> Maybe x)
Flows.flowStateValue TTerm (FlowState Any Any -> Maybe Any)
-> TTerm (FlowState Any Any) -> TTerm (Maybe Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f1") (String -> TTerm Any
forall a. String -> TTerm a
var String
"cx1") (TTerm (FlowState Any Any -> Trace)
forall s x. TTerm (FlowState s x -> Trace)
Flows.flowStateTrace TTerm (FlowState Any Any -> Trace)
-> TTerm (FlowState Any Any) -> TTerm Trace
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (FlowState Any Any)
forall a. String -> TTerm a
var String
"f1"))
      TTerm (FlowState Any Any) -> [Field] -> TTerm (FlowState Any Any)
forall a. TTerm a -> [Field] -> TTerm a
`with` [
        String
"f1"String -> TTerm (FlowState Any Any) -> Field
forall a. String -> TTerm a -> Field
>:
          Type -> TTerm (FlowState Any Any) -> TTerm (FlowState Any Any)
forall a. Type -> TTerm a -> TTerm a
typed (Type -> Type -> Type
Types.apply (Type -> Type -> Type
Types.apply (Name -> Type
TypeVariable Name
_FlowState) (String -> Type
Types.var String
"s1")) (String -> Type
Types.var String
"a")) (TTerm (FlowState Any Any) -> TTerm (FlowState Any Any))
-> TTerm (FlowState Any Any) -> TTerm (FlowState Any Any)
forall a b. (a -> b) -> a -> b
$
          TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
forall s x. TTerm (Flow s x -> s -> Trace -> FlowState s x)
Flows.unFlow TTerm (Flow Any Any -> Any -> Trace -> FlowState Any Any)
-> TTerm (Flow Any Any)
-> TTerm (Any -> Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Flow Any Any)
forall a. String -> TTerm a
var String
"f" TTerm (Any -> Trace -> FlowState Any Any)
-> TTerm Any -> TTerm (Trace -> FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Any
forall a. String -> TTerm a
var String
"cx0" TTerm (Trace -> FlowState Any Any)
-> TTerm Trace -> TTerm (FlowState Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t1"])

withTraceDef :: TElement (String -> Flow s a -> Flow s a)
withTraceDef :: forall s a. TElement (String -> Flow s a -> Flow s a)
withTraceDef = String
-> TTerm (String -> Flow s a -> Flow s a)
-> TElement (String -> Flow s a -> Flow s a)
forall a. String -> TTerm a -> TElement a
tier1Definition String
"withTrace" (TTerm (String -> Flow s a -> Flow s a)
 -> TElement (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TElement (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a. String -> TTerm a -> TTerm a
doc String
"Continue the current flow after augmenting the trace" (TTerm (String -> Flow s a -> Flow s a)
 -> TTerm (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  [Type]
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a. [Type] -> TTerm a -> TTerm a
functionN [Type
Types.string, Type
flowSAT, Type
flowSAT] (TTerm (String -> Flow s a -> Flow s a)
 -> TTerm (String -> Flow s a -> Flow s a))
-> TTerm (String -> Flow s a -> Flow s a)
-> TTerm (String -> Flow s a -> Flow s a)
forall a b. (a -> b) -> a -> b
$
  String
-> TTerm (Flow Any Any -> Flow Any Any)
-> TTerm (String -> Flow s a -> Flow s a)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"msg" ((TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
-> TTerm
     ((Trace -> Either_ String Trace)
      -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
forall a. TElement a -> TTerm a
ref TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
forall s a.
TElement
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow s a -> Flow s a)
mutateTraceDef TTerm
  ((Trace -> Either_ String Trace)
   -> (Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
-> TTerm (Trace -> Either_ String Trace)
-> TTerm
     ((Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Trace -> Either_ String Trace)
forall a. String -> TTerm a
var String
"mutate" TTerm ((Trace -> Trace -> Trace) -> Flow Any Any -> Flow Any Any)
-> TTerm (Trace -> Trace -> Trace)
-> TTerm (Flow Any Any -> Flow Any Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm (Trace -> Trace -> Trace)
forall a. String -> TTerm a
var String
"restore")
    TTerm (Flow Any Any -> Flow Any Any)
-> [Field] -> TTerm (Flow Any Any -> Flow Any Any)
forall a. TTerm a -> [Field] -> TTerm a
`with` [
      -- augment the trace
      String
"mutate"String -> TTerm (Any -> Any) -> Field
forall a. String -> TTerm a -> Field
>: String -> TTerm Any -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t" (TTerm Any -> TTerm (Any -> Any))
-> TTerm Any -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm (Any -> Any -> Bool -> Any)
forall a. TTerm (a -> a -> Bool -> a)
Logic.ifElse
        TTerm (Any -> Any -> Bool -> Any)
-> TTerm Any -> TTerm (Any -> Bool -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (Name -> Name -> TTerm String -> TTerm Any
forall a b. Name -> Name -> TTerm a -> TTerm b
inject Name
_Either Name
_Either_left (TTerm String -> TTerm Any) -> TTerm String -> TTerm Any
forall a b. (a -> b) -> a -> b
$ String -> TTerm String
string String
"maximum trace depth exceeded. This may indicate an infinite loop")
        TTerm (Any -> Bool -> Any) -> TTerm Any -> TTerm (Bool -> Any)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (Name -> Name -> TTerm Trace -> TTerm Any
forall a b. Name -> Name -> TTerm a -> TTerm b
inject Name
_Either Name
_Either_right (TTerm Trace -> TTerm Any) -> TTerm Trace -> TTerm Any
forall a b. (a -> b) -> a -> b
$ TTerm [String]
-> TTerm [String] -> TTerm (Map String Term) -> TTerm Trace
Flows.trace
          (TTerm (String -> [String] -> [String])
forall a. TTerm (a -> [a] -> [a])
Lists.cons TTerm (String -> [String] -> [String])
-> TTerm String -> TTerm ([String] -> [String])
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm String
forall a. String -> TTerm a
var String
"msg" TTerm ([String] -> [String]) -> TTerm [String] -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t"))
          (TTerm (Trace -> [String])
Flows.traceMessages TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t")
          (TTerm (Trace -> Map String Term)
Flows.traceOther TTerm (Trace -> Map String Term)
-> TTerm Trace -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t"))
        TTerm (Bool -> Any) -> TTerm Bool -> TTerm Any
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Int -> Int -> Bool)
Equality.gteInt32 TTerm (Int -> Int -> Bool) -> TTerm Int -> TTerm (Int -> Bool)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm ([String] -> Int)
forall a. TTerm ([a] -> Int)
Lists.length TTerm ([String] -> Int) -> TTerm [String] -> TTerm Int
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t")) TTerm (Int -> Bool) -> TTerm Int -> TTerm Bool
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ TElement Int -> TTerm Int
forall a. TElement a -> TTerm a
ref TElement Int
maxTraceDepthDef),
      -- reset the trace stack after execution
      String
"restore"String -> TTerm (Any -> Any) -> Field
forall a. String -> TTerm a -> Field
>: String -> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t0" (TTerm (Any -> Any) -> TTerm (Any -> Any))
-> TTerm (Any -> Any) -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ String -> TTerm Trace -> TTerm (Any -> Any)
forall x a b. String -> TTerm x -> TTerm (a -> b)
lambda String
"t1" (TTerm Trace -> TTerm (Any -> Any))
-> TTerm Trace -> TTerm (Any -> Any)
forall a b. (a -> b) -> a -> b
$ TTerm [String]
-> TTerm [String] -> TTerm (Map String Term) -> TTerm Trace
Flows.trace
        (TTerm (Trace -> [String])
Flows.traceStack TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t0")
        (TTerm (Trace -> [String])
Flows.traceMessages TTerm (Trace -> [String]) -> TTerm Trace -> TTerm [String]
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t1")
        (TTerm (Trace -> Map String Term)
Flows.traceOther TTerm (Trace -> Map String Term)
-> TTerm Trace -> TTerm (Map String Term)
forall a b. TTerm (a -> b) -> TTerm a -> TTerm b
@@ String -> TTerm Trace
forall a. String -> TTerm a
var String
"t1")])