-- SPDX-FileCopyrightText: 2020 Tocqueville Group
--
-- SPDX-License-Identifier: LicenseRef-MIT-TQ

-- | All the basic 'Expr'essions used in Indigo code.
--
-- Note: infix operators acting on structure follow a naming convention:
--
-- 1. the last character identifies the structure type:
--
--      - @:@ for containers ('Map', 'BigMap', 'Set', 'List')
--      - @\@@ for 'UStore'
--      - @!@ for 'HasField'
--      - @~@ fot 'Util.Named'
--
-- 2. the preceding characters identify the action:
--
--      - @#@ for get, lookup or from
--      - @!@ for set, update or to
--      - @+@ for insert
--      - @++@ for insertNew
--      - @-@ for remove
--      - @?@ for mem or elem
--
-- The only exception to this convention is '(.:)' (for 'cons')

module Indigo.Internal.Expr.Symbolic
  ( -- * Basic
    constExpr, varExpr, cast

  -- * Math
  , add, sub, mul, div, mod, neg, abs
  , (+), (-), (*), (/), (%)

  -- * Comparison
  , eq, neq, lt, gt, le, ge
  , (==), (/=), (<), (>), (<=), (>=)

  -- * Conversion
  , isNat, toInt, nonZero

  -- * Bits and boolean
  , lsl, lsr, and, or, xor, not
  , (<<<), (>>>), (&&), (||), (^)

  -- * Serialization
  , pack, unpack

  -- * Pairs
  , pair, car, cdr, fst, snd

  -- * Maybe
  , some, none

  -- * Either
  , right, left

  -- * Bytes and string
  , slice, concat, (<>)

  -- * List
  , concatAll, nil, cons, (.:)

  -- * Containers
  , get, update, insert, remove, mem, size
  , (#:), (!:), (+:), (-:), (?:)
  , empty, emptyBigMap, emptyMap, emptySet

  -- * UStore
  , uGet, uUpdate, uInsert, uInsertNew, uDelete, uMem
  , (#@), (!@), (+@), (++@), (-@), (?@)

  -- * HasField
  , (!!), (#!)

  -- * Record and Named
  , name, unName, (!~), (#~)
  , construct, constructRec

  -- * Contract
  , contract
  , self
  , contractAddress
  , contractCallingUnsafe
  , contractCallingString
  , runFutureContract
  , implicitAccount
  , convertEpAddressToContract
  , makeView
  , makeVoid

  -- * Auxiliary
  , now
  , amount
  , sender
  , blake2b
  , sha256
  , sha512
  , hashKey
  , chainId
  , balance
  , checkSignature
  ) where

import Data.Vinyl.Core (RMap(..))

import Indigo.Internal.Expr.Types
import Indigo.Internal.Field
import Indigo.Internal.Object (Var)
import Indigo.Lorentz
import Indigo.Prelude
import qualified Michelson.Typed.Arith as M
import Util.TypeTuple
import Michelson.Text (unMText)
import Michelson.Untyped.EntryPoints (unsafeBuildEpName)

----------------------------------------------------------------------------
-- Basic
----------------------------------------------------------------------------

constExpr :: NiceConstant a => a -> Expr a
constExpr :: a -> Expr a
constExpr = a -> Expr a
forall a. NiceConstant a => a -> Expr a
C

-- | Create an expression holding a variable.
varExpr :: KnownValue a => Var a -> Expr a
varExpr :: Var a -> Expr a
varExpr = Var a -> Expr a
forall a. KnownValue a => Var a -> Expr a
V

cast :: (ex :~> a) => ex -> Expr a
cast :: ex -> Expr a
cast = ex -> Expr a
forall ex a. (ex :~> a) => ex -> Expr a
Cast

----------------------------------------------------------------------------
-- Math
----------------------------------------------------------------------------

infixl 6 +
add, (+)
  :: IsArithExpr exN exM M.Add n m
  => exN -> exM
  -> Expr (ArithResHs M.Add n m)
add :: exN -> exM -> Expr (ArithResHs Add n m)
add = exN -> exM -> Expr (ArithResHs Add n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Add ex1 ex2,
 KnownValue (ArithResHs Add ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Add ex1 ex2)
Add
+ :: exN -> exM -> Expr (ArithResHs Add n m)
(+) = exN -> exM -> Expr (ArithResHs Add n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Add ex1 ex2,
 KnownValue (ArithResHs Add ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Add ex1 ex2)
Add

infixl 6 -
sub, (-)
  :: IsArithExpr exN exM M.Sub n m
  => exN -> exM
  -> Expr (ArithResHs M.Sub n m)
sub :: exN -> exM -> Expr (ArithResHs Sub n m)
sub = exN -> exM -> Expr (ArithResHs Sub n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Sub ex1 ex2,
 KnownValue (ArithResHs Sub ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Sub ex1 ex2)
Sub
(-) = exN -> exM -> Expr (ArithResHs Sub n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Sub ex1 ex2,
 KnownValue (ArithResHs Sub ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Sub ex1 ex2)
Sub

infixl 7 *
mul, (*)
  :: IsArithExpr exN exM M.Mul n m
  => exN -> exM
  -> Expr (ArithResHs M.Mul n m)
mul :: exN -> exM -> Expr (ArithResHs Mul n m)
mul = exN -> exM -> Expr (ArithResHs Mul n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Mul ex1 ex2,
 KnownValue (ArithResHs Mul ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Mul ex1 ex2)
Mul
* :: exN -> exM -> Expr (ArithResHs Mul n m)
(*) = exN -> exM -> Expr (ArithResHs Mul n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Mul ex1 ex2,
 KnownValue (ArithResHs Mul ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Mul ex1 ex2)
Mul

infixl 7 /
div, (/)
  :: IsDivExpr exN exM n m
  => exN -> exM
  -> Expr (EDivOpResHs n m)
div :: exN -> exM -> Expr (EDivOpResHs n m)
div = exN -> exM -> Expr (EDivOpResHs n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, EDivOpHs ex1 ex2,
 KnownValue (EDivOpResHs ex1 ex2)) =>
ex1 -> ex2 -> Expr (EDivOpResHs ex1 ex2)
Div
/ :: exN -> exM -> Expr (EDivOpResHs n m)
(/) = exN -> exM -> Expr (EDivOpResHs n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, EDivOpHs ex1 ex2,
 KnownValue (EDivOpResHs ex1 ex2)) =>
ex1 -> ex2 -> Expr (EDivOpResHs ex1 ex2)
Div

infixl 7 %
mod, (%)
  :: IsModExpr exN exM n m
  => exN -> exM
  -> Expr (EModOpResHs n m)
mod :: exN -> exM -> Expr (EModOpResHs n m)
mod = exN -> exM -> Expr (EModOpResHs n m)
forall ex1 ex2 ex ex.
(AreExprs ex1 ex2 ex ex, EDivOpHs ex ex,
 KnownValue (EModOpResHs ex ex)) =>
ex1 -> ex2 -> Expr (EModOpResHs ex ex)
Mod
% :: exN -> exM -> Expr (EModOpResHs n m)
(%) = exN -> exM -> Expr (EModOpResHs n m)
forall ex1 ex2 ex ex.
(AreExprs ex1 ex2 ex ex, EDivOpHs ex ex,
 KnownValue (EModOpResHs ex ex)) =>
ex1 -> ex2 -> Expr (EModOpResHs ex ex)
Mod

abs
  :: IsUnaryArithExpr exN M.Abs n
  => exN
  -> Expr (UnaryArithResHs M.Abs n)
abs :: exN -> Expr (UnaryArithResHs Abs n)
abs = exN -> Expr (UnaryArithResHs Abs n)
forall ex ex.
(IsExpr ex ex, UnaryArithOpHs Abs ex,
 KnownValue (UnaryArithResHs Abs ex)) =>
ex -> Expr (UnaryArithResHs Abs ex)
Abs

neg
  :: IsUnaryArithExpr exN M.Neg n
  => exN
  -> Expr (UnaryArithResHs M.Neg n)
neg :: exN -> Expr (UnaryArithResHs Neg n)
neg = exN -> Expr (UnaryArithResHs Neg n)
forall ex ex1.
(IsExpr ex ex1, UnaryArithOpHs Neg ex1,
 KnownValue (UnaryArithResHs Neg ex1)) =>
ex -> Expr (UnaryArithResHs Neg ex1)
Neg

----------------------------------------------------------------------------
-- Comparison
----------------------------------------------------------------------------

infix 4 ==
eq, (==)
  :: (NiceComparable n, AreExprs c c1 n n)
  => c -> c1
  -> Expr Bool
eq :: c -> c1 -> Expr Bool
eq = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Eq'
== :: c -> c1 -> Expr Bool
(==) = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Eq'

infix 4 /=
neq, (/=)
  :: (NiceComparable n, AreExprs c c1 n n)
  => c -> c1
  -> Expr Bool
neq :: c -> c1 -> Expr Bool
neq = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Neq
/= :: c -> c1 -> Expr Bool
(/=) = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Neq

infix 4 <
lt, (<)
  :: (NiceComparable n, AreExprs c c1 n n)
  => c -> c1
  -> Expr Bool
lt :: c -> c1 -> Expr Bool
lt = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Lt
< :: c -> c1 -> Expr Bool
(<) = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Lt

infix 4 >
gt, (>)
  :: (NiceComparable n, AreExprs c c1 n n)
  => c -> c1
  -> Expr Bool
gt :: c -> c1 -> Expr Bool
gt = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Gt
> :: c -> c1 -> Expr Bool
(>) = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Gt

infix 4 <=
le, (<=)
  :: (NiceComparable n, AreExprs c c1 n n)
  => c -> c1
  -> Expr Bool
le :: c -> c1 -> Expr Bool
le = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Le
<= :: c -> c1 -> Expr Bool
(<=) = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Le

infix 4 >=
ge, (>=)
  :: (NiceComparable n, AreExprs c c1 n n)
  => c -> c1
  -> Expr Bool
ge :: c -> c1 -> Expr Bool
ge = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Ge
>= :: c -> c1 -> Expr Bool
(>=) = c -> c1 -> Expr Bool
forall n m n.
(AreExprs n m n n, NiceComparable n) =>
n -> m -> Expr Bool
Ge

----------------------------------------------------------------------------
-- Conversion
----------------------------------------------------------------------------

isNat :: (ex :~> Integer) => ex -> Expr (Maybe Natural)
isNat :: ex -> Expr (Maybe Natural)
isNat = ex -> Expr (Maybe Natural)
forall ex. IsExpr ex Integer => ex -> Expr (Maybe Natural)
IsNat

toInt :: (ex :~> Natural) => ex -> Expr Integer
toInt :: ex -> Expr Integer
toInt = ex -> Expr Integer
forall n. IsExpr n Natural => n -> Expr Integer
Int'

nonZero :: (ex :~> n, NonZero n, KnownValue (Maybe n)) => ex -> Expr (Maybe n)
nonZero :: ex -> Expr (Maybe n)
nonZero = ex -> Expr (Maybe n)
forall ex n.
(IsExpr ex n, NonZero n, KnownValue (Maybe n)) =>
ex -> Expr (Maybe n)
NonZero

----------------------------------------------------------------------------
-- Bits and boolean
----------------------------------------------------------------------------

infixl 8 <<<
lsl, (<<<)
  :: IsArithExpr exN exM M.Lsl n m
  => exN -> exM
  -> Expr (ArithResHs M.Lsl n m)
lsl :: exN -> exM -> Expr (ArithResHs Lsl n m)
lsl = exN -> exM -> Expr (ArithResHs Lsl n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Lsl ex1 ex2,
 KnownValue (ArithResHs Lsl ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Lsl ex1 ex2)
Lsl
<<< :: exN -> exM -> Expr (ArithResHs Lsl n m)
(<<<) = exN -> exM -> Expr (ArithResHs Lsl n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Lsl ex1 ex2,
 KnownValue (ArithResHs Lsl ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Lsl ex1 ex2)
Lsl

infixl 8 >>>
lsr, (>>>)
  :: IsArithExpr exN exM M.Lsr n m
  => exN -> exM
  -> Expr (ArithResHs M.Lsr n m)
lsr :: exN -> exM -> Expr (ArithResHs Lsr n m)
lsr = exN -> exM -> Expr (ArithResHs Lsr n m)
forall ex1 ex2 n m.
(AreExprs ex1 ex2 n m, ArithOpHs Lsr n m,
 KnownValue (ArithResHs Lsr n m)) =>
ex1 -> ex2 -> Expr (ArithResHs Lsr n m)
Lsr
>>> :: exN -> exM -> Expr (ArithResHs Lsr n m)
(>>>) = exN -> exM -> Expr (ArithResHs Lsr n m)
forall ex1 ex2 n m.
(AreExprs ex1 ex2 n m, ArithOpHs Lsr n m,
 KnownValue (ArithResHs Lsr n m)) =>
ex1 -> ex2 -> Expr (ArithResHs Lsr n m)
Lsr

infixr 2 ||
or, (||)
  :: IsArithExpr exN exM M.Or n m
  => exN -> exM
  -> Expr (ArithResHs M.Or n m)
or :: exN -> exM -> Expr (ArithResHs Or n m)
or = exN -> exM -> Expr (ArithResHs Or n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Or ex1 ex2,
 KnownValue (ArithResHs Or ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Or ex1 ex2)
Or
|| :: exN -> exM -> Expr (ArithResHs Or n m)
(||) = exN -> exM -> Expr (ArithResHs Or n m)
forall ex1 ex2 ex1 ex2.
(AreExprs ex1 ex2 ex1 ex2, ArithOpHs Or ex1 ex2,
 KnownValue (ArithResHs Or ex1 ex2)) =>
ex1 -> ex2 -> Expr (ArithResHs Or ex1 ex2)
Or

infixr 3 &&
and, (&&)
  :: IsArithExpr exN exM M.And n m
  => exN -> exM
  -> Expr (ArithResHs M.And n m)
and :: exN -> exM -> Expr (ArithResHs And n m)
and = exN -> exM -> Expr (ArithResHs And n m)
forall n m op n.
(AreExprs n m op n, ArithOpHs And op n,
 KnownValue (ArithResHs And op n)) =>
n -> m -> Expr (ArithResHs And op n)
And
&& :: exN -> exM -> Expr (ArithResHs And n m)
(&&) = exN -> exM -> Expr (ArithResHs And n m)
forall n m op n.
(AreExprs n m op n, ArithOpHs And op n,
 KnownValue (ArithResHs And op n)) =>
n -> m -> Expr (ArithResHs And op n)
And

infixr 2 ^
xor, (^)
  :: IsArithExpr exN exM M.Xor n m
  => exN -> exM
  -> Expr (ArithResHs M.Xor n m)
xor :: exN -> exM -> Expr (ArithResHs Xor n m)
xor = exN -> exM -> Expr (ArithResHs Xor n m)
forall ex1 ex2 n m.
(AreExprs ex1 ex2 n m, ArithOpHs Xor n m,
 KnownValue (ArithResHs Xor n m)) =>
ex1 -> ex2 -> Expr (ArithResHs Xor n m)
Xor
^ :: exN -> exM -> Expr (ArithResHs Xor n m)
(^) = exN -> exM -> Expr (ArithResHs Xor n m)
forall ex1 ex2 n m.
(AreExprs ex1 ex2 n m, ArithOpHs Xor n m,
 KnownValue (ArithResHs Xor n m)) =>
ex1 -> ex2 -> Expr (ArithResHs Xor n m)
Xor

not
  :: IsUnaryArithExpr exN M.Not n
  => exN
  -> Expr (UnaryArithResHs M.Not n)
not :: exN -> Expr (UnaryArithResHs Not n)
not = exN -> Expr (UnaryArithResHs Not n)
forall op n.
(IsExpr op n, UnaryArithOpHs Not n,
 KnownValue (UnaryArithResHs Not n)) =>
op -> Expr (UnaryArithResHs Not n)
Not

----------------------------------------------------------------------------
-- Serialization
----------------------------------------------------------------------------

pack :: (IsExpr ex a, NicePackedValue a) => ex -> Expr ByteString
pack :: ex -> Expr ByteString
pack = ex -> Expr ByteString
forall key a.
(IsExpr key a, NicePackedValue a) =>
key -> Expr ByteString
Pack

unpack :: (NiceUnpackedValue a, exb :~> ByteString) => exb -> Expr (Maybe a)
unpack :: exb -> Expr (Maybe a)
unpack = exb -> Expr (Maybe a)
forall a ex1.
(NiceUnpackedValue a, IsExpr ex1 ByteString) =>
ex1 -> Expr (Maybe a)
Unpack

----------------------------------------------------------------------------
-- Pairs
----------------------------------------------------------------------------

pair :: (AreExprs ex1 ex2 n m, KnownValue (n, m)) => ex1 -> ex2 -> Expr (n, m)
pair :: ex1 -> ex2 -> Expr (n, m)
pair = ex1 -> ex2 -> Expr (n, m)
forall ex1 ex2 ex t.
(AreExprs ex1 ex2 ex t, KnownValue (ex, t)) =>
ex1 -> ex2 -> Expr (ex, t)
Pair

car, fst :: (op :~> (n, m), KnownValue n) => op -> Expr n
car :: op -> Expr n
car = op -> Expr n
forall op n op. (IsExpr op (n, op), KnownValue n) => op -> Expr n
Fst
fst :: op -> Expr n
fst = op -> Expr n
forall op n op. (IsExpr op (n, op), KnownValue n) => op -> Expr n
Fst

cdr, snd :: (op :~> (n, m), KnownValue m) => op -> Expr m
cdr :: op -> Expr m
cdr = op -> Expr m
forall op n m. (IsExpr op (n, m), KnownValue m) => op -> Expr m
Snd
snd :: op -> Expr m
snd = op -> Expr m
forall op n m. (IsExpr op (n, m), KnownValue m) => op -> Expr m
Snd

----------------------------------------------------------------------------
-- Maybe
----------------------------------------------------------------------------

some :: (ex :~> t, KnownValue (Maybe t)) => ex -> Expr (Maybe t)
some :: ex -> Expr (Maybe t)
some = ex -> Expr (Maybe t)
forall ex t.
(IsExpr ex t, KnownValue (Maybe t)) =>
ex -> Expr (Maybe t)
Some

none :: KnownValue t => Expr (Maybe t)
none :: Expr (Maybe t)
none = Expr (Maybe t)
forall t. KnownValue t => Expr (Maybe t)
None

----------------------------------------------------------------------------
-- Either
----------------------------------------------------------------------------

right :: (ex :~> x, KnownValue y, KnownValue (Either y x)) => ex -> Expr (Either y x)
right :: ex -> Expr (Either y x)
right = ex -> Expr (Either y x)
forall ex x y.
(IsExpr ex x, KnownValue y, KnownValue (Either y x)) =>
ex -> Expr (Either y x)
Right'

left :: (ex :~> y, KnownValue x, KnownValue (Either y x)) => ex -> Expr (Either y x)
left :: ex -> Expr (Either y x)
left = ex -> Expr (Either y x)
forall ex y x.
(IsExpr ex y, KnownValue x, KnownValue (Either y x)) =>
ex -> Expr (Either y x)
Left'

----------------------------------------------------------------------------
-- Bytes and string
----------------------------------------------------------------------------

slice
  :: ( an :~> Natural
     , bn :~> Natural
     , IsSliceExpr ex c
     )
  => (an, bn) -> ex
  -> Expr (Maybe c)
slice :: (an, bn) -> ex -> Expr (Maybe c)
slice (a :: an
a, b :: bn
b) = an -> bn -> ex -> Expr (Maybe c)
forall ex c p addr.
(IsExpr ex c, SliceOpHs c, IsExpr p Natural,
 IsExpr addr Natural) =>
p -> addr -> ex -> Expr (Maybe c)
Slice an
a bn
b

infixr 6 <>
concat, (<>)
  :: IsConcatExpr exN1 exN2 n
  => exN1 -> exN2
  -> Expr n
concat :: exN1 -> exN2 -> Expr n
concat = exN1 -> exN2 -> Expr n
forall ex2 c ex.
(IsExpr ex2 c, IsExpr ex c, ConcatOpHs c) =>
ex2 -> ex -> Expr c
Concat
<> :: exN1 -> exN2 -> Expr n
(<>) = exN1 -> exN2 -> Expr n
forall ex2 c ex.
(IsExpr ex2 c, IsExpr ex c, ConcatOpHs c) =>
ex2 -> ex -> Expr c
Concat

----------------------------------------------------------------------------
-- List
----------------------------------------------------------------------------

infixr 5 .:
cons, (.:) :: (ex1 :~> a, ex2 :~> List a) => ex1 -> ex2 -> Expr (List a)
cons :: ex1 -> ex2 -> Expr (List a)
cons = ex1 -> ex2 -> Expr (List a)
forall ex1 a ex2.
(IsExpr ex1 a, IsExpr ex2 (List a)) =>
ex1 -> ex2 -> Expr (List a)
Cons
.: :: ex1 -> ex2 -> Expr (List a)
(.:) = ex1 -> ex2 -> Expr (List a)
forall ex1 a ex2.
(IsExpr ex1 a, IsExpr ex2 (List a)) =>
ex1 -> ex2 -> Expr (List a)
Cons

concatAll :: IsConcatListExpr exN n => exN -> Expr n
concatAll :: exN -> Expr n
concatAll = exN -> Expr n
forall ex c.
(IsExpr ex (List c), ConcatOpHs c, KnownValue c) =>
ex -> Expr c
Concat'

nil :: KnownValue a => Expr (List a)
nil :: Expr (List a)
nil = Expr (List a)
forall a. KnownValue a => Expr (List a)
Nil

----------------------------------------------------------------------------
-- Containers
----------------------------------------------------------------------------

class ExprMagma c where
  empty :: (NiceComparable (UpdOpKeyHs c), KnownValue c) => Expr c

instance KnownValue v => ExprMagma (BigMap k v) where
  empty :: Expr (BigMap k v)
empty = Expr (BigMap k v)
forall key key.
(KnownValue key, NiceComparable key,
 KnownValue (BigMap key key)) =>
Expr (BigMap key key)
EmptyBigMap

instance KnownValue v => ExprMagma (Map k v) where
  empty :: Expr (Map k v)
empty = Expr (Map k v)
forall value key.
(KnownValue value, NiceComparable key,
 KnownValue (Map key value)) =>
Expr (Map key value)
EmptyMap

instance ExprMagma (Set k) where
  empty :: Expr (Set k)
empty = Expr (Set k)
forall key.
(NiceComparable key, KnownValue (Set key)) =>
Expr (Set key)
EmptySet

-- | Expression class to insert an element into a data structure.
--
-- Note that while this is based on 'update' and 'UpdOpHs', it is necessary to
-- have different instances to allow for different 'update' parameter types,
-- ('Set' uses a 'Bool' instead of a 'Maybe'), just like 'ExprRemovable'.
--
-- Moreover, this class is parameterized with an @insParam@ as well in order to
-- have both key-value pairs ('Map' and 'BigMap') as well as key only ('Set').
class UpdOpHs c => ExprInsertable c insParam where
  insert :: ex :~> c => insParam -> ex -> Expr c

instance (NiceComparable k, exKey :~> k, exValue :~> v)
    => ExprInsertable (BigMap k v) (exKey, exValue) where
  insert :: (exKey, exValue) -> ex -> Expr (BigMap k v)
insert (k :: exKey
k, v :: exValue
v) c :: ex
c = ex -> exKey -> Expr (Maybe v) -> Expr (BigMap k v)
forall c exKey exVal exStructure.
(UpdOpHs c, IsExpr exKey (UpdOpKeyHs c),
 IsExpr exVal (UpdOpParamsHs c), IsExpr exStructure c) =>
exStructure -> exKey -> exVal -> Expr c
Update ex
c exKey
k (exValue -> Expr (Maybe v)
forall ex t.
(IsExpr ex t, KnownValue (Maybe t)) =>
ex -> Expr (Maybe t)
some exValue
v)

instance (NiceComparable k, exKey :~> k, exValue :~> v)
    => ExprInsertable (Map k v) (exKey, exValue) where
  insert :: (exKey, exValue) -> ex -> Expr (Map k v)
insert (k :: exKey
k, v :: exValue
v) c :: ex
c = ex -> exKey -> Expr (Maybe v) -> Expr (Map k v)
forall c exKey exVal exStructure.
(UpdOpHs c, IsExpr exKey (UpdOpKeyHs c),
 IsExpr exVal (UpdOpParamsHs c), IsExpr exStructure c) =>
exStructure -> exKey -> exVal -> Expr c
Update ex
c exKey
k (exValue -> Expr (Maybe v)
forall ex t.
(IsExpr ex t, KnownValue (Maybe t)) =>
ex -> Expr (Maybe t)
some exValue
v)

instance (NiceComparable a, exKey :~> a) => ExprInsertable (Set a) exKey where
  insert :: exKey -> ex -> Expr (Set a)
insert k :: exKey
k c :: ex
c = ex -> exKey -> Bool -> Expr (Set a)
forall c exKey exVal exStructure.
(UpdOpHs c, IsExpr exKey (UpdOpKeyHs c),
 IsExpr exVal (UpdOpParamsHs c), IsExpr exStructure c) =>
exStructure -> exKey -> exVal -> Expr c
Update ex
c exKey
k Bool
True

-- | Expression class to remove an element from a data structure.
--
-- Note that while this is based on 'update' and 'UpdOpHs', it is necessary to
-- have different instances to allow for different 'update' parameter types,
-- ('Set' uses a 'Bool' instead of a 'Maybe').
class UpdOpHs c => ExprRemovable c where
  remove
    :: (exStruct :~> c, exKey :~> UpdOpKeyHs c)
    => exKey -> exStruct -> Expr c

instance (NiceComparable k, KnownValue v) => ExprRemovable (BigMap k v) where
  remove :: exKey -> exStruct -> Expr (BigMap k v)
remove k :: exKey
k c :: exStruct
c = exStruct -> exKey -> Expr (Maybe v) -> Expr (BigMap k v)
forall c exKey exVal exStructure.
(UpdOpHs c, IsExpr exKey (UpdOpKeyHs c),
 IsExpr exVal (UpdOpParamsHs c), IsExpr exStructure c) =>
exStructure -> exKey -> exVal -> Expr c
Update exStruct
c exKey
k Expr (Maybe v)
forall t. KnownValue t => Expr (Maybe t)
none

instance (NiceComparable k, KnownValue v) => ExprRemovable (Map k v) where
  remove :: exKey -> exStruct -> Expr (Map k v)
remove k :: exKey
k c :: exStruct
c = exStruct -> exKey -> Expr (Maybe v) -> Expr (Map k v)
forall c exKey exVal exStructure.
(UpdOpHs c, IsExpr exKey (UpdOpKeyHs c),
 IsExpr exVal (UpdOpParamsHs c), IsExpr exStructure c) =>
exStructure -> exKey -> exVal -> Expr c
Update exStruct
c exKey
k Expr (Maybe v)
forall t. KnownValue t => Expr (Maybe t)
none

instance NiceComparable a => ExprRemovable (Set a) where
  remove :: exKey -> exStruct -> Expr (Set a)
remove k :: exKey
k c :: exStruct
c = exStruct -> exKey -> Bool -> Expr (Set a)
forall c exKey exVal exStructure.
(UpdOpHs c, IsExpr exKey (UpdOpKeyHs c),
 IsExpr exVal (UpdOpParamsHs c), IsExpr exStructure c) =>
exStructure -> exKey -> exVal -> Expr c
Update exStruct
c exKey
k Bool
False

get
  :: IsGetExpr exKey exMap map
  => exKey -> exMap
  -> Expr (Maybe (GetOpValHs map))
get :: exKey -> exMap -> Expr (Maybe (GetOpValHs map))
get = exKey -> exMap -> Expr (Maybe (GetOpValHs map))
forall c exKey exMap.
(GetOpHs c, KnownValue (Maybe (GetOpValHs c)),
 IsExpr exKey (GetOpKeyHs c), IsExpr exMap c,
 KnownValue (GetOpValHs c)) =>
exKey -> exMap -> Expr (Maybe (GetOpValHs c))
Get

update
  :: IsUpdExpr exKey exVal exMap map
  => (exKey, exVal) -> exMap
  -> Expr map
update :: (exKey, exVal) -> exMap -> Expr map
update (k :: exKey
k, v :: exVal
v) s :: exMap
s = exMap -> exKey -> exVal -> Expr map
forall c exKey exVal exStructure.
(UpdOpHs c, IsExpr exKey (UpdOpKeyHs c),
 IsExpr exVal (UpdOpParamsHs c), IsExpr exStructure c) =>
exStructure -> exKey -> exVal -> Expr c
Update exMap
s exKey
k exVal
v

mem
  :: IsMemExpr exKey exN n
  => exKey -> exN
  -> Expr Bool
mem :: exKey -> exN -> Expr Bool
mem = exKey -> exN -> Expr Bool
forall c exc exck.
(MemOpHs c, IsExpr exc c, IsExpr exck (MemOpKeyHs c)) =>
exck -> exc -> Expr Bool
Mem

size
  :: IsSizeExpr exN n
  => exN -> Expr Natural
size :: exN -> Expr Natural
size = exN -> Expr Natural
forall exc c. (IsExpr exc c, SizeOpHs c) => exc -> Expr Natural
Size

infixl 8 #:
(#:)
  :: IsGetExpr exKey exMap map
  => exMap -> exKey
  -> Expr (Maybe (GetOpValHs map))
#: :: exMap -> exKey -> Expr (Maybe (GetOpValHs map))
(#:) = (exKey -> exMap -> Expr (Maybe (GetOpValHs map)))
-> exMap -> exKey -> Expr (Maybe (GetOpValHs map))
forall a b c. (a -> b -> c) -> b -> a -> c
flip exKey -> exMap -> Expr (Maybe (GetOpValHs map))
forall exKey exMap map.
IsGetExpr exKey exMap map =>
exKey -> exMap -> Expr (Maybe (GetOpValHs map))
get

infixl 8 !:
(!:)
  :: IsUpdExpr exKey exVal exMap map
  => exMap -> (exKey, exVal)
  -> Expr map
!: :: exMap -> (exKey, exVal) -> Expr map
(!:) = ((exKey, exVal) -> exMap -> Expr map)
-> exMap -> (exKey, exVal) -> Expr map
forall a b c. (a -> b -> c) -> b -> a -> c
flip (exKey, exVal) -> exMap -> Expr map
forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update

infixl 8 +:
(+:)
  :: ( ExprInsertable c exParam
     , exStructure :~> c
     )
     => exStructure -> exParam
     -> Expr c
+: :: exStructure -> exParam -> Expr c
(+:) = (exParam -> exStructure -> Expr c)
-> exStructure -> exParam -> Expr c
forall a b c. (a -> b -> c) -> b -> a -> c
flip exParam -> exStructure -> Expr c
forall c insParam ex.
(ExprInsertable c insParam, ex :~> c) =>
insParam -> ex -> Expr c
insert

infixl 8 -:
(-:)
  :: ( ExprRemovable c
     , exStruct :~> c
     , exKey :~> UpdOpKeyHs c
     )
  => exStruct -> exKey
  -> Expr c
-: :: exStruct -> exKey -> Expr c
(-:) = (exKey -> exStruct -> Expr c) -> exStruct -> exKey -> Expr c
forall a b c. (a -> b -> c) -> b -> a -> c
flip exKey -> exStruct -> Expr c
forall c exStruct exKey.
(ExprRemovable c, exStruct :~> c, exKey :~> UpdOpKeyHs c) =>
exKey -> exStruct -> Expr c
remove

infixl 8 ?:
(?:)
  :: IsMemExpr exKey exN n
  => exN -> exKey
  -> Expr Bool
?: :: exN -> exKey -> Expr Bool
(?:) = (exKey -> exN -> Expr Bool) -> exN -> exKey -> Expr Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip exKey -> exN -> Expr Bool
forall exKey exN n.
IsMemExpr exKey exN n =>
exKey -> exN -> Expr Bool
mem

emptyBigMap
  :: (KnownValue value, NiceComparable key, KnownValue (BigMap key value))
  => Expr (BigMap key value)
emptyBigMap :: Expr (BigMap key value)
emptyBigMap = Expr (BigMap key value)
forall c.
(ExprMagma c, NiceComparable (UpdOpKeyHs c), KnownValue c) =>
Expr c
empty

emptyMap
  :: (KnownValue value, NiceComparable key, KnownValue (Map key value))
  => Expr (Map key value)
emptyMap :: Expr (Map key value)
emptyMap = Expr (Map key value)
forall c.
(ExprMagma c, NiceComparable (UpdOpKeyHs c), KnownValue c) =>
Expr c
empty

emptySet
  :: (NiceComparable key, KnownValue (Set key))
  => Expr (Set key)
emptySet :: Expr (Set key)
emptySet = Expr (Set key)
forall c.
(ExprMagma c, NiceComparable (UpdOpKeyHs c), KnownValue c) =>
Expr c
empty

----------------------------------------------------------------------------
-- UStore
----------------------------------------------------------------------------

infixr 8 #@
uGet, (#@)
  :: ( HasUStore name key value store
     , exKey   :~> key
     , exStore :~> (UStore store)
     )
  => exStore -> (Label name, exKey)
  -> Expr (Maybe value)
uGet :: exStore -> (Label name, exKey) -> Expr (Maybe value)
uGet store :: exStore
store (uName :: Label name
uName, key :: exKey
key) = Label name -> exKey -> exStore -> Expr (Maybe value)
forall (name :: Symbol) key value name key value.
(HasUStore name key value name, IsExpr key key,
 IsExpr value (UStore name), KnownValue value) =>
Label name -> key -> value -> Expr (Maybe value)
UGet Label name
uName exKey
key exStore
store
#@ :: exStore -> (Label name, exKey) -> Expr (Maybe value)
(#@) = exStore -> (Label name, exKey) -> Expr (Maybe value)
forall (name :: Symbol) key value store exKey exStore.
(HasUStore name key value store, exKey :~> key,
 exStore :~> UStore store) =>
exStore -> (Label name, exKey) -> Expr (Maybe value)
uGet

infixl 8 !@
uUpdate, (!@)
  :: ( HasUStore name key value store
     , exKey   :~> key
     , exVal   :~> Maybe value
     , exStore :~> UStore store
     )
  => exStore -> (Label name, exKey, exVal)
  -> Expr (UStore store)
uUpdate :: exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
uUpdate store :: exStore
store (uName :: Label name
uName, key :: exKey
key, val :: exVal
val) = Label name -> exKey -> exVal -> exStore -> Expr (UStore store)
forall (store :: Symbol) exKey exStore store exKey exVal exStore.
(HasUStore store exKey exStore store, exKey :~> exKey,
 exVal :~> Maybe exStore, exStore :~> UStore store) =>
Label store -> exKey -> exVal -> exStore -> Expr (UStore store)
UUpdate Label name
uName exKey
key exVal
val exStore
store
!@ :: exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
(!@) = exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
forall (name :: Symbol) key value store exKey exVal exStore.
(HasUStore name key value store, exKey :~> key,
 exVal :~> Maybe value, exStore :~> UStore store) =>
exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
uUpdate

infixr 8 +@
uInsert, (+@)
  :: ( HasUStore name key value store
     , exKey   :~> key
     , exVal   :~> value
     , exStore :~> UStore store
     )
  => exStore -> (Label name, exKey, exVal)
  -> Expr (UStore store)
uInsert :: exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
uInsert store :: exStore
store (uName :: Label name
uName, key :: exKey
key, val :: exVal
val) = Label name -> exKey -> exVal -> exStore -> Expr (UStore store)
forall (err :: Symbol) exKey exVal exStore exKey exVal exStore.
(HasUStore err exKey exVal exStore, IsExpr exKey exKey,
 IsExpr exVal exVal, IsExpr exStore (UStore exStore)) =>
Label err -> exKey -> exVal -> exStore -> Expr (UStore exStore)
UInsert Label name
uName exKey
key exVal
val exStore
store
+@ :: exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
(+@) = exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
forall (name :: Symbol) key value store exKey exVal exStore.
(HasUStore name key value store, exKey :~> key, exVal :~> value,
 exStore :~> UStore store) =>
exStore -> (Label name, exKey, exVal) -> Expr (UStore store)
uInsert

infixr 8 ++@
uInsertNew, (++@)
  :: ( HasUStore name key value store
     , IsError err
     , exKey   :~> key
     , exVal   :~> value
     , exStore :~> UStore store
     )
  => exStore
  -> (Label name, err, exKey, exVal)
  -> Expr (UStore store)
uInsertNew :: exStore -> (Label name, err, exKey, exVal) -> Expr (UStore store)
uInsertNew store :: exStore
store (uName :: Label name
uName, err :: err
err, key :: exKey
key, val :: exVal
val) = Label name
-> err -> exKey -> exVal -> exStore -> Expr (UStore store)
forall (name :: Symbol) key value store err exKey exVal exStore.
(HasUStore name key value store, IsError err, IsExpr exKey key,
 IsExpr exVal value, IsExpr exStore (UStore store)) =>
Label name
-> err -> exKey -> exVal -> exStore -> Expr (UStore store)
UInsertNew Label name
uName err
err exKey
key exVal
val exStore
store
++@ :: exStore -> (Label name, err, exKey, exVal) -> Expr (UStore store)
(++@) = exStore -> (Label name, err, exKey, exVal) -> Expr (UStore store)
forall (name :: Symbol) key value store err exKey exVal exStore.
(HasUStore name key value store, IsError err, exKey :~> key,
 exVal :~> value, exStore :~> UStore store) =>
exStore -> (Label name, err, exKey, exVal) -> Expr (UStore store)
uInsertNew

infixl 8 -@
uDelete, (-@)
  :: ( HasUStore name key value store
     , exKey   :~> key
     , exStore :~> (UStore store)
     )
  => exStore -> (Label name, exKey)
  -> Expr (UStore store)
uDelete :: exStore -> (Label name, exKey) -> Expr (UStore store)
uDelete store :: exStore
store (uName :: Label name
uName, key :: exKey
key) = Label name -> exKey -> exStore -> Expr (UStore store)
forall (name :: Symbol) key val store ex t.
(HasUStore name key val store, ex :~> key, t :~> UStore store) =>
Label name -> ex -> t -> Expr (UStore store)
UDelete Label name
uName exKey
key exStore
store
-@ :: exStore -> (Label name, exKey) -> Expr (UStore store)
(-@) = exStore -> (Label name, exKey) -> Expr (UStore store)
forall (name :: Symbol) key value store exKey exStore.
(HasUStore name key value store, exKey :~> key,
 exStore :~> UStore store) =>
exStore -> (Label name, exKey) -> Expr (UStore store)
uDelete

infixl 8 ?@
uMem, (?@)
  :: ( HasUStore name key value store
     , exKey   :~> key
     , exStore :~> (UStore store)
     )
  => exStore -> (Label name, exKey)
  -> Expr Bool
uMem :: exStore -> (Label name, exKey) -> Expr Bool
uMem store :: exStore
store (uName :: Label name
uName, key :: exKey
key) = Label name -> exKey -> exStore -> Expr Bool
forall (name :: Symbol) key val store exKey exStore.
(HasUStore name key val store, exKey :~> key,
 exStore :~> UStore store, KnownValue val) =>
Label name -> exKey -> exStore -> Expr Bool
UMem Label name
uName exKey
key exStore
store
?@ :: exStore -> (Label name, exKey) -> Expr Bool
(?@) = exStore -> (Label name, exKey) -> Expr Bool
forall (name :: Symbol) key value store exKey exStore.
(HasUStore name key value store, exKey :~> key,
 exStore :~> UStore store) =>
exStore -> (Label name, exKey) -> Expr Bool
uMem

----------------------------------------------------------------------------
-- HasField
----------------------------------------------------------------------------

infixl 8 #!
(#!)
  :: (HasField dt name ftype, exDt :~> dt)
  => exDt
  -> Label name
  -> Expr ftype
#! :: exDt -> Label name -> Expr ftype
(#!) (exDt -> Expr (ExprType exDt)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr -> (ObjMan fa :: ObjectManipulation (ExprType exDt)
fa)) fName :: Label name
fName = ObjectManipulation ftype -> Expr ftype
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt -> Label name -> ObjectManipulation ftype
forall dt (fname :: Symbol) ftype.
HasField dt fname ftype =>
ObjectManipulation dt -> Label fname -> ObjectManipulation ftype
ToField ObjectManipulation dt
ObjectManipulation (ExprType exDt)
fa Label name
fName)
(#!) exDt :: exDt
exDt fName :: Label name
fName = ObjectManipulation ftype -> Expr ftype
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt -> Label name -> ObjectManipulation ftype
forall dt (fname :: Symbol) ftype.
HasField dt fname ftype =>
ObjectManipulation dt -> Label fname -> ObjectManipulation ftype
ToField (Expr dt -> ObjectManipulation dt
forall a. Expr a -> ObjectManipulation a
Object (Expr dt -> ObjectManipulation dt)
-> Expr dt -> ObjectManipulation dt
forall a b. (a -> b) -> a -> b
$ exDt -> Expr (ExprType exDt)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exDt
exDt) Label name
fName)

infixl 8 !!
(!!)
  :: ( HasField dt name ftype
     , exDt :~> dt
     , exFld :~> ftype
     )
  => exDt
  -> (Label name, exFld)
  -> Expr dt
!! :: exDt -> (Label name, exFld) -> Expr dt
(!!) (exDt -> Expr (ExprType exDt)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr -> (ObjMan fa :: ObjectManipulation (ExprType exDt)
fa)) (fName :: Label name
fName, fld :: exFld
fld) = ObjectManipulation dt -> Expr dt
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt
-> Label name -> Expr ftype -> ObjectManipulation dt
forall dt (fname :: Symbol) ftype.
HasField dt fname ftype =>
ObjectManipulation dt
-> Label fname -> Expr ftype -> ObjectManipulation dt
SetField ObjectManipulation dt
ObjectManipulation (ExprType exDt)
fa Label name
fName (exFld -> Expr (ExprType exFld)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exFld
fld))
dt :: exDt
dt !! (fName :: Label name
fName, fld :: exFld
fld) = ObjectManipulation dt -> Expr dt
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt
-> Label name -> Expr ftype -> ObjectManipulation dt
forall dt (fname :: Symbol) ftype.
HasField dt fname ftype =>
ObjectManipulation dt
-> Label fname -> Expr ftype -> ObjectManipulation dt
SetField (Expr dt -> ObjectManipulation dt
forall a. Expr a -> ObjectManipulation a
Object (Expr dt -> ObjectManipulation dt)
-> Expr dt -> ObjectManipulation dt
forall a b. (a -> b) -> a -> b
$ exDt -> Expr (ExprType exDt)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exDt
dt) Label name
fName (exFld -> Expr (ExprType exFld)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exFld
fld))

----------------------------------------------------------------------------
-- Record and Named
----------------------------------------------------------------------------

name :: (ex :~> t, KnownValue (name :! t)) => Label name -> ex -> Expr (name :! t)
name :: Label name -> ex -> Expr (name :! t)
name = Label name -> ex -> Expr (name :! t)
forall ex t (name :: Symbol).
(IsExpr ex t, KnownValue (name :! t)) =>
Label name -> ex -> Expr (name :! t)
Name

unName :: (ex :~> (name :! t), KnownValue t) => Label name -> ex -> Expr t
unName :: Label name -> ex -> Expr t
unName = Label name -> ex -> Expr t
forall ex (name :: Symbol) t.
(IsExpr ex (name :! t), KnownValue t) =>
Label name -> ex -> Expr t
UnName

infixl 8 !~
(!~)
  :: (ex :~> t, KnownValue (name :! t))
  => ex -> Label name
  -> Expr (name :! t)
!~ :: ex -> Label name -> Expr (name :! t)
(!~) = (Label name -> ex -> Expr (name :! t))
-> ex -> Label name -> Expr (name :! t)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Label name -> ex -> Expr (name :! t)
forall ex t (name :: Symbol).
(IsExpr ex t, KnownValue (name :! t)) =>
Label name -> ex -> Expr (name :! t)
name

infixl 8 #~
(#~)
  :: (ex :~> (name :! t), KnownValue t)
  => ex -> Label name
  -> Expr t
#~ :: ex -> Label name -> Expr t
(#~) = (Label name -> ex -> Expr t) -> ex -> Label name -> Expr t
forall a b c. (a -> b -> c) -> b -> a -> c
flip Label name -> ex -> Expr t
forall ex (name :: Symbol) t.
(IsExpr ex (name :! t), KnownValue t) =>
Label name -> ex -> Expr t
unName

construct
  :: ( InstrConstructC dt, KnownValue dt
     , RMap (ConstructorFieldTypes dt)
     , fields ~ Rec Expr (ConstructorFieldTypes dt)
     , RecFromTuple fields
     )
  => IsoRecTuple fields -> Expr dt
construct :: IsoRecTuple fields -> Expr dt
construct = Rec Expr (GFieldTypes (Rep dt)) -> Expr dt
forall dt.
(InstrConstructC dt, RMap (ConstructorFieldTypes dt),
 KnownValue dt) =>
Rec Expr (ConstructorFieldTypes dt) -> Expr dt
Construct (Rec Expr (GFieldTypes (Rep dt)) -> Expr dt)
-> (IsoRecTuple (Rec Expr (GFieldTypes (Rep dt)))
    -> Rec Expr (GFieldTypes (Rep dt)))
-> IsoRecTuple (Rec Expr (GFieldTypes (Rep dt)))
-> Expr dt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IsoRecTuple (Rec Expr (GFieldTypes (Rep dt)))
-> Rec Expr (GFieldTypes (Rep dt))
forall r. RecFromTuple r => IsoRecTuple r -> r
recFromTuple

constructRec
  :: ( InstrConstructC dt
     , RMap (ConstructorFieldTypes dt)
     , KnownValue dt
     )
  => Rec Expr (ConstructorFieldTypes dt)
  -> Expr dt
constructRec :: Rec Expr (ConstructorFieldTypes dt) -> Expr dt
constructRec = Rec Expr (ConstructorFieldTypes dt) -> Expr dt
forall dt.
(InstrConstructC dt, RMap (ConstructorFieldTypes dt),
 KnownValue dt) =>
Rec Expr (ConstructorFieldTypes dt) -> Expr dt
Construct

----------------------------------------------------------------------------
-- Contract
----------------------------------------------------------------------------

contract
  :: ( NiceParameterFull p
     , NoExplicitDefaultEntryPoint p
     , ToTAddress p addr
     , ToT addr ~ ToT Address
     , exAddr :~> addr
     )
  => exAddr -> Expr (Maybe (ContractRef p))
contract :: exAddr -> Expr (Maybe (ContractRef p))
contract = exAddr -> Expr (Maybe (ContractRef p))
forall p addr exc.
(NiceParameterFull p, NoExplicitDefaultEntryPoint p,
 ToTAddress p addr, ToT addr ~ ToT Address, IsExpr exc addr) =>
exc -> Expr (Maybe (ContractRef p))
Contract

self
  :: ( NiceParameterFull p
     , NoExplicitDefaultEntryPoint p
     )
  => Expr (ContractRef p)
self :: Expr (ContractRef p)
self = Expr (ContractRef p)
forall p.
(NiceParameterFull p, NoExplicitDefaultEntryPoint p) =>
Expr (ContractRef p)
Self

contractAddress :: (exc :~> ContractRef p) => exc -> Expr Address
contractAddress :: exc -> Expr Address
contractAddress = exc -> Expr Address
forall exc arg. IsExpr exc (ContractRef arg) => exc -> Expr Address
ContractAddress

contractCallingUnsafe
  :: ( NiceParameter arg
     , exAddr :~> Address
     )
  => EpName -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingUnsafe :: EpName -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingUnsafe = EpName -> exAddr -> Expr (Maybe (ContractRef arg))
forall arg p.
(NiceParameter arg, IsExpr p Address) =>
EpName -> p -> Expr (Maybe (ContractRef arg))
ContractCallingUnsafe

contractCallingString
  :: ( NiceParameter arg
     , exAddr :~> Address
     )
  => MText -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingString :: MText -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingString =
    EpName -> exAddr -> Expr (Maybe (ContractRef arg))
forall arg p.
(NiceParameter arg, IsExpr p Address) =>
EpName -> p -> Expr (Maybe (ContractRef arg))
contractCallingUnsafe
  (EpName -> exAddr -> Expr (Maybe (ContractRef arg)))
-> (MText -> EpName)
-> MText
-> exAddr
-> Expr (Maybe (ContractRef arg))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> EpName
unsafeBuildEpName
  (Text -> EpName) -> (MText -> Text) -> MText -> EpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MText -> Text
unMText

runFutureContract
  :: ( NiceParameter p
     , conExpr :~> FutureContract p
     )
  => conExpr -> Expr (Maybe (ContractRef p))
runFutureContract :: conExpr -> Expr (Maybe (ContractRef p))
runFutureContract = conExpr -> Expr (Maybe (ContractRef p))
forall p exkh.
(NiceParameter p, IsExpr exkh (FutureContract p)) =>
exkh -> Expr (Maybe (ContractRef p))
RunFutureContract

implicitAccount
  :: (exkh :~> KeyHash)
  => exkh
  -> Expr (ContractRef ())
implicitAccount :: exkh -> Expr (ContractRef ())
implicitAccount = exkh -> Expr (ContractRef ())
forall exkh. IsExpr exkh KeyHash => exkh -> Expr (ContractRef ())
ImplicitAccount

convertEpAddressToContract
  :: ( NiceParameter p
     , epExpr :~> EpAddress
     )
  => epExpr -> Expr (Maybe (ContractRef p))
convertEpAddressToContract :: epExpr -> Expr (Maybe (ContractRef p))
convertEpAddressToContract = epExpr -> Expr (Maybe (ContractRef p))
forall p a.
(NiceParameter p, IsExpr a EpAddress) =>
a -> Expr (Maybe (ContractRef p))
ConvertEpAddressToContract

makeView
  :: ( KnownValue (View a r)
     , exa :~> a
     , exCRef :~> ContractRef r
     )
  => exa -> exCRef -> Expr (View a r)
makeView :: exa -> exCRef -> Expr (View a r)
makeView = exa -> exCRef -> Expr (View a r)
forall a r a b.
(KnownValue (View a r), a :~> a, b :~> ContractRef r) =>
a -> b -> Expr (View a r)
MakeView

makeVoid
  :: ( KnownValue (Void_ a b)
     , exa :~> a
     , exCRef :~> Lambda b b
     )
  => exa -> exCRef -> Expr (Void_ a b)
makeVoid :: exa -> exCRef -> Expr (Void_ a b)
makeVoid = exa -> exCRef -> Expr (Void_ a b)
forall a b pkExpr sigExpr.
(KnownValue (Void_ a b), pkExpr :~> a, sigExpr :~> Lambda b b) =>
pkExpr -> sigExpr -> Expr (Void_ a b)
MakeVoid

----------------------------------------------------------------------------
-- Auxiliary
----------------------------------------------------------------------------

now :: Expr Timestamp
now :: Expr Timestamp
now = Expr Timestamp
Now

amount :: Expr Mutez
amount :: Expr Mutez
amount = Expr Mutez
Amount

sender :: Expr Address
sender :: Expr Address
sender = Expr Address
Sender

checkSignature
  :: ( pkExpr :~> PublicKey
     , sigExpr :~> Signature
     , hashExpr :~> ByteString
     )
  => pkExpr -> sigExpr -> hashExpr
  -> Expr Bool
checkSignature :: pkExpr -> sigExpr -> hashExpr -> Expr Bool
checkSignature = pkExpr -> sigExpr -> hashExpr -> Expr Bool
forall pkExpr sigExpr hashExpr.
(IsExpr pkExpr PublicKey, IsExpr sigExpr Signature,
 IsExpr hashExpr ByteString) =>
pkExpr -> sigExpr -> hashExpr -> Expr Bool
CheckSignature

sha256 :: (hashExpr :~> ByteString) => hashExpr -> Expr ByteString
sha256 :: hashExpr -> Expr ByteString
sha256 = hashExpr -> Expr ByteString
forall hashExpr.
IsExpr hashExpr ByteString =>
hashExpr -> Expr ByteString
Sha256

sha512 :: (hashExpr :~> ByteString) => hashExpr -> Expr ByteString
sha512 :: hashExpr -> Expr ByteString
sha512 = hashExpr -> Expr ByteString
forall hashExpr.
IsExpr hashExpr ByteString =>
hashExpr -> Expr ByteString
Sha512

blake2b :: (hashExpr :~> ByteString) => hashExpr -> Expr ByteString
blake2b :: hashExpr -> Expr ByteString
blake2b = hashExpr -> Expr ByteString
forall hashExpr.
IsExpr hashExpr ByteString =>
hashExpr -> Expr ByteString
Blake2b

hashKey :: (keyExpr :~> PublicKey) => keyExpr -> Expr KeyHash
hashKey :: keyExpr -> Expr KeyHash
hashKey = keyExpr -> Expr KeyHash
forall keyExpr. IsExpr keyExpr PublicKey => keyExpr -> Expr KeyHash
HashKey

chainId :: Expr ChainId
chainId :: Expr ChainId
chainId = Expr ChainId
ChainId

balance :: Expr Mutez
balance :: Expr Mutez
balance = Expr Mutez
Balance