-- SPDX-FileCopyrightText: 2021 Oxhead Alpha
-- SPDX-License-Identifier: LicenseRef-MIT-OA

-- | 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 storage operations (@MEM@, @GET@, @UPDATE@)
--      - @!@ 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.Frontend.Expr
  ( -- * Basic
    constExpr, varExpr, cast

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

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

  -- * Conversion
  , isNat, toInt, nonZero, coerce, forcedCoerce

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

  -- * Serialization
  , pack, unpack
  , packRaw, unpackRaw

  -- * 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

  -- * Storages
  , stGet, stUpdate, stInsert, stInsertNew, stDelete, stMem
  , (#@), (!@), (+@), (++@), (-@), (?@)

  -- * Sum types
  , wrap, unwrap

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

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

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

  -- * Auxiliary
  , now
  , amount
  , sender
  , blake2b
  , sha256
  , sha512
  , sha3
  , keccak
  , hashKey
  , chainId
  , balance
  , level
  , votingPower
  , totalVotingPower
  , checkSignature
  ) where

import Data.Vinyl.Core (RMap(..), RecordToList(..))
import Fmt (Buildable)

import Indigo.Backend.Prelude (fromInteger)
import Indigo.Common.Expr
import Indigo.Common.Field
import Indigo.Common.Var (Var)
import Indigo.Lorentz hiding (forcedCoerce)
import Indigo.Prelude
import Morley.Michelson.Text (unMText)
import Morley.Michelson.Typed.Arith qualified as M
import Morley.Michelson.Typed.Haskell.Instr.Sum (CtorOnlyField, InstrUnwrapC, InstrWrapOneC)
import Morley.Michelson.Untyped.Entrypoints (buildEpName)
import Morley.Util.TypeTuple

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

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

-- | Create an expression holding a variable.
varExpr :: KnownValue a => Var a -> Expr a
varExpr :: forall a. KnownValue a => 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 :: forall ex a. (ex :~> a) => ex -> Expr a
cast = Expr a -> Expr a
forall a. KnownValue a => Expr a -> Expr a
Cast (Expr a -> Expr a) -> (ex -> Expr a) -> ex -> Expr a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr a
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

infixl 6 +
add, (+)
  :: IsArithExpr exN exM M.Add n m r
  => exN -> exM
  -> Expr r
add :: forall exN exM n m r.
IsArithExpr exN exM Add n m r =>
exN -> exM -> Expr r
add exN
n exM
m = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs Add n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
Add (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
n) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
m)
+ :: forall exN exM n m r.
IsArithExpr exN exM Add n m r =>
exN -> exM -> Expr r
(+) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM Add n m r =>
exN -> exM -> Expr r
add

infixl 6 -
sub, (-)
  :: IsArithExpr exN exM M.Sub n m r
  => exN -> exM
  -> Expr r
sub :: forall exN exM n m r.
IsArithExpr exN exM Sub n m r =>
exN -> exM -> Expr r
sub exN
n exM
m = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs Sub n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
Sub (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
n) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
m)
(-) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM Sub n m r =>
exN -> exM -> Expr r
sub

infixl 7 *
mul, (*)
  :: IsArithExpr exN exM M.Mul n m r
  => exN -> exM
  -> Expr r
mul :: forall exN exM n m r.
IsArithExpr exN exM Mul n m r =>
exN -> exM -> Expr r
mul exN
n exM
m = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs Mul n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
Mul (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
n) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
m)
* :: forall exN exM n m r.
IsArithExpr exN exM Mul n m r =>
exN -> exM -> Expr r
(*) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM Mul n m r =>
exN -> exM -> Expr r
mul

infixl 7 /
div, (/)
  :: forall reminder exN exM n m ratio. IsDivExpr exN exM n m ratio reminder
  => exN -> exM
  -> Expr ratio
div :: forall reminder exN exM n m ratio.
IsDivExpr exN exM n m ratio reminder =>
exN -> exM -> Expr ratio
div exN
n exM
m = Expr n -> Expr m -> Proxy reminder -> Expr ratio
forall a n m reminder.
(KnownValue a, ArithOpHs EDiv n m (Maybe (a, reminder))) =>
Expr n -> Expr m -> Proxy reminder -> Expr a
Div (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
n) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
m) (Proxy reminder
forall {k} (t :: k). Proxy t
Proxy :: Proxy reminder)
/ :: forall reminder exN exM n m ratio.
IsDivExpr exN exM n m ratio reminder =>
exN -> exM -> Expr ratio
(/) = forall reminder exN exM n m ratio.
IsDivExpr exN exM n m ratio reminder =>
exN -> exM -> Expr ratio
div @reminder

infixl 7 %
mod, (%)
  :: forall ratio exN exM n m reminder. IsModExpr exN exM n m ratio reminder
  => exN -> exM
  -> Expr reminder
mod :: forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
mod exN
n exM
m = Expr n -> Expr m -> Proxy ratio -> Expr reminder
forall a n m ratio.
(KnownValue a, ArithOpHs EDiv n m (Maybe (ratio, a))) =>
Expr n -> Expr m -> Proxy ratio -> Expr a
Mod (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
n) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
m) (Proxy ratio
forall {k} (t :: k). Proxy t
Proxy :: Proxy ratio)
% :: forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
(%) = forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
mod @ratio

abs
  :: IsUnaryArithExpr exN M.Abs n
  => exN
  -> Expr (UnaryArithResHs M.Abs n)
abs :: forall exN n.
IsUnaryArithExpr exN Abs n =>
exN -> Expr (UnaryArithResHs Abs n)
abs = Expr n -> Expr (UnaryArithResHs Abs n)
forall n.
(UnaryArithOpHs Abs n, KnownValue (UnaryArithResHs Abs n)) =>
Expr n -> Expr (UnaryArithResHs Abs n)
Abs (Expr n -> Expr (UnaryArithResHs Abs n))
-> (exN -> Expr n) -> exN -> Expr (UnaryArithResHs Abs n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exN -> Expr n
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

neg
  :: IsUnaryArithExpr exN M.Neg n
  => exN
  -> Expr (UnaryArithResHs M.Neg n)
neg :: forall exN n.
IsUnaryArithExpr exN Neg n =>
exN -> Expr (UnaryArithResHs Neg n)
neg = Expr n -> Expr (UnaryArithResHs Neg n)
forall n.
(UnaryArithOpHs Neg n, KnownValue (UnaryArithResHs Neg n)) =>
Expr n -> Expr (UnaryArithResHs Neg n)
Neg (Expr n -> Expr (UnaryArithResHs Neg n))
-> (exN -> Expr n) -> exN -> Expr (UnaryArithResHs Neg n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exN -> Expr n
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

class ParityExpr n m where
  even :: (ArithOpHs M.EDiv n m r, exN :~> n) => exN -> Expr Bool
  odd  :: (ArithOpHs M.EDiv n m r, exN :~> n) => exN -> Expr Bool

instance ParityExpr Integer Integer where
  even :: forall r exN.
(ArithOpHs EDiv Integer Integer r, exN :~> Integer) =>
exN -> Expr Bool
even = Natural -> Expr Natural -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
eq (Natural
0 :: Natural) (Expr Natural -> Expr Bool)
-> (exN -> Expr Natural) -> exN -> Expr Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (exN -> Natural -> Expr Natural
forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
`mod` (Natural
2 :: Natural))
  odd :: forall r exN.
(ArithOpHs EDiv Integer Integer r, exN :~> Integer) =>
exN -> Expr Bool
odd = Natural -> Expr Natural -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
neq (Natural
0 :: Natural) (Expr Natural -> Expr Bool)
-> (exN -> Expr Natural) -> exN -> Expr Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (exN -> Natural -> Expr Natural
forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
`mod` (Natural
2 :: Natural))

instance ParityExpr Natural Natural where
  even :: forall r exN.
(ArithOpHs EDiv Natural Natural r, exN :~> Natural) =>
exN -> Expr Bool
even = Natural -> Expr Natural -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
eq (Natural
0 :: Natural) (Expr Natural -> Expr Bool)
-> (exN -> Expr Natural) -> exN -> Expr Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (exN -> Natural -> Expr Natural
forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
`mod` (Natural
2 :: Natural))
  odd :: forall r exN.
(ArithOpHs EDiv Natural Natural r, exN :~> Natural) =>
exN -> Expr Bool
odd = Natural -> Expr Natural -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
neq (Natural
0 :: Natural) (Expr Natural -> Expr Bool)
-> (exN -> Expr Natural) -> exN -> Expr Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (exN -> Natural -> Expr Natural
forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
`mod` (Natural
2 :: Natural))

instance ParityExpr Mutez Mutez where
  even :: forall r exN.
(ArithOpHs EDiv Mutez Mutez r, exN :~> Mutez) =>
exN -> Expr Bool
even = Mutez -> Expr Mutez -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
eq Mutez
zeroMutez (Expr Mutez -> Expr Bool)
-> (exN -> Expr Mutez) -> exN -> Expr Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (exN -> Mutez -> Expr Mutez
forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
`mod` [tz|2u|])
  odd :: forall r exN.
(ArithOpHs EDiv Mutez Mutez r, exN :~> Mutez) =>
exN -> Expr Bool
odd = Mutez -> Expr Mutez -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
neq Mutez
zeroMutez (Expr Mutez -> Expr Bool)
-> (exN -> Expr Mutez) -> exN -> Expr Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (exN -> Mutez -> Expr Mutez
forall ratio exN exM n m reminder.
IsModExpr exN exM n m ratio reminder =>
exN -> exM -> Expr reminder
`mod` [tz|2u|])

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

infix 4 ==
eq, (==)
  :: (NiceComparable n, c :~> n, c1 :~> n)
  => c -> c1
  -> Expr Bool
eq :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
eq c
a c1
b = Expr n -> Expr n -> Expr Bool
forall n. NiceComparable n => Expr n -> Expr n -> Expr Bool
Eq' (c -> Expr (ExprType c)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c
a) (c1 -> Expr (ExprType c1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c1
b)
== :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
(==) = c -> c1 -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
eq

infix 4 /=
neq, (/=)
  :: (NiceComparable n, c :~> n, c1 :~> n)
  => c -> c1
  -> Expr Bool
neq :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
neq c
a c1
b = Expr n -> Expr n -> Expr Bool
forall n. NiceComparable n => Expr n -> Expr n -> Expr Bool
Neq (c -> Expr (ExprType c)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c
a) (c1 -> Expr (ExprType c1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c1
b)
/= :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
(/=) = c -> c1 -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
neq

infix 4 <
lt, (<)
  :: (NiceComparable n, c :~> n, c1 :~> n)
  => c -> c1
  -> Expr Bool
lt :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
lt c
a c1
b = Expr n -> Expr n -> Expr Bool
forall n. NiceComparable n => Expr n -> Expr n -> Expr Bool
Lt (c -> Expr (ExprType c)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c
a) (c1 -> Expr (ExprType c1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c1
b)
< :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
(<) = c -> c1 -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
lt

infix 4 >
gt, (>)
  :: (NiceComparable n, c :~> n, c1 :~> n)
  => c -> c1
  -> Expr Bool
gt :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
gt c
a c1
b = Expr n -> Expr n -> Expr Bool
forall n. NiceComparable n => Expr n -> Expr n -> Expr Bool
Gt (c -> Expr (ExprType c)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c
a) (c1 -> Expr (ExprType c1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c1
b)
> :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
(>) = c -> c1 -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
gt

infix 4 <=
le, (<=)
  :: (NiceComparable n, c :~> n, c1 :~> n)
  => c -> c1
  -> Expr Bool
le :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
le c
a c1
b = Expr n -> Expr n -> Expr Bool
forall n. NiceComparable n => Expr n -> Expr n -> Expr Bool
Le (c -> Expr (ExprType c)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c
a) (c1 -> Expr (ExprType c1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c1
b)
<= :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
(<=) = c -> c1 -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
le

infix 4 >=
ge, (>=)
  :: (NiceComparable n, c :~> n, c1 :~> n)
  => c -> c1
  -> Expr Bool
ge :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
ge c
a c1
b = Expr n -> Expr n -> Expr Bool
forall n. NiceComparable n => Expr n -> Expr n -> Expr Bool
Ge (c -> Expr (ExprType c)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c
a) (c1 -> Expr (ExprType c1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr c1
b)
>= :: forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
(>=) = c -> c1 -> Expr Bool
forall n c c1.
(NiceComparable n, c :~> n, c1 :~> n) =>
c -> c1 -> Expr Bool
ge

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

isNat :: (ex :~> Integer) => ex -> Expr (Maybe Natural)
isNat :: forall ex. (ex :~> Integer) => ex -> Expr (Maybe Natural)
isNat = Expr Integer -> Expr (Maybe Natural)
IsNat (Expr Integer -> Expr (Maybe Natural))
-> (ex -> Expr Integer) -> ex -> Expr (Maybe Natural)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr Integer
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

toInt :: (ex :~> Natural) => ex -> Expr Integer
toInt :: forall ex. (ex :~> Natural) => ex -> Expr Integer
toInt = Expr Natural -> Expr Integer
Int' (Expr Natural -> Expr Integer)
-> (ex -> Expr Natural) -> ex -> Expr Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr Natural
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

nonZero :: (ex :~> n, NonZero n, KnownValue (Maybe n)) => ex -> Expr (Maybe n)
nonZero :: forall ex n.
(ex :~> n, NonZero n, KnownValue (Maybe n)) =>
ex -> Expr (Maybe n)
nonZero = Expr n -> Expr (Maybe n)
forall n.
(NonZero n, KnownValue (Maybe n)) =>
Expr n -> Expr (Maybe n)
NonZero (Expr n -> Expr (Maybe n))
-> (ex -> Expr n) -> ex -> Expr (Maybe n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr n
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

-- | Convert between types that have the same Michelson representation and an
-- explicit permission for that in the face of 'CanCastTo' constraint.
coerce :: forall b a ex. (Castable_ a b, KnownValue b, ex :~> a) => ex -> Expr b
coerce :: forall b a ex.
(Castable_ a b, KnownValue b, ex :~> a) =>
ex -> Expr b
coerce = Expr a -> Expr b
forall a1 a. (Castable_ a1 a, KnownValue a) => Expr a1 -> Expr a
Coerce (Expr a -> Expr b) -> (ex -> Expr a) -> ex -> Expr b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr a
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

-- | Convert between expressions of types that have the same Michelson
-- representation.
forcedCoerce
  :: forall b a ex. (MichelsonCoercible a b, KnownValue b, ex :~> a)
  => ex -> Expr b
forcedCoerce :: forall b a ex.
(MichelsonCoercible a b, KnownValue b, ex :~> a) =>
ex -> Expr b
forcedCoerce = Expr a -> Expr b
forall a1 a.
(MichelsonCoercible a1 a, KnownValue a) =>
Expr a1 -> Expr a
ForcedCoerce (Expr a -> Expr b) -> (ex -> Expr a) -> ex -> Expr b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr a
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

infixl 8 <<<
lsl, (<<<)
  :: IsArithExpr exN exM M.Lsl n m r
  => exN -> exM
  -> Expr r
lsl :: forall exN exM n m r.
IsArithExpr exN exM Lsl n m r =>
exN -> exM -> Expr r
lsl exN
a exM
b = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs Lsl n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
Lsl (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
a) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
b)
<<< :: forall exN exM n m r.
IsArithExpr exN exM Lsl n m r =>
exN -> exM -> Expr r
(<<<) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM Lsl n m r =>
exN -> exM -> Expr r
lsl

infixl 8 >>>
lsr, (>>>)
  :: IsArithExpr exN exM M.Lsr n m r
  => exN -> exM
  -> Expr r
lsr :: forall exN exM n m r.
IsArithExpr exN exM Lsr n m r =>
exN -> exM -> Expr r
lsr exN
a exM
b = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs Lsr n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
Lsr (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
a) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
b)
>>> :: forall exN exM n m r.
IsArithExpr exN exM Lsr n m r =>
exN -> exM -> Expr r
(>>>) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM Lsr n m r =>
exN -> exM -> Expr r
lsr

infixr 2 ||
or, (||)
  :: IsArithExpr exN exM M.Or n m r
  => exN -> exM
  -> Expr r
or :: forall exN exM n m r.
IsArithExpr exN exM Or n m r =>
exN -> exM -> Expr r
or exN
a exM
b = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs Or n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
Or (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
a) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
b)
|| :: forall exN exM n m r.
IsArithExpr exN exM Or n m r =>
exN -> exM -> Expr r
(||) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM Or n m r =>
exN -> exM -> Expr r
or

infixr 3 &&
and, (&&)
  :: IsArithExpr exN exM M.And n m r
  => exN -> exM
  -> Expr r
and :: forall exN exM n m r.
IsArithExpr exN exM And n m r =>
exN -> exM -> Expr r
and exN
a exM
b = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs And n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
And (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
a) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
b)
&& :: forall exN exM n m r.
IsArithExpr exN exM And n m r =>
exN -> exM -> Expr r
(&&) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM And n m r =>
exN -> exM -> Expr r
and

infixr 2 ^
xor, (^)
  :: IsArithExpr exN exM M.Xor n m r
  => exN -> exM
  -> Expr r
xor :: forall exN exM n m r.
IsArithExpr exN exM Xor n m r =>
exN -> exM -> Expr r
xor exN
a exM
b = Expr n -> Expr m -> Expr r
forall n m a.
(ArithOpHs Xor n m a, KnownValue a) =>
Expr n -> Expr m -> Expr a
Xor (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
a) (exM -> Expr (ExprType exM)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exM
b)
^ :: forall exN exM n m r.
IsArithExpr exN exM Xor n m r =>
exN -> exM -> Expr r
(^) = exN -> exM -> Expr r
forall exN exM n m r.
IsArithExpr exN exM Xor n m r =>
exN -> exM -> Expr r
xor

not
  :: IsUnaryArithExpr exN M.Not n
  => exN
  -> Expr (UnaryArithResHs M.Not n)
not :: forall exN n.
IsUnaryArithExpr exN Not n =>
exN -> Expr (UnaryArithResHs Not n)
not = Expr n -> Expr (UnaryArithResHs Not n)
forall n.
(UnaryArithOpHs Not n, KnownValue (UnaryArithResHs Not n)) =>
Expr n -> Expr (UnaryArithResHs Not n)
Not (Expr n -> Expr (UnaryArithResHs Not n))
-> (exN -> Expr n) -> exN -> Expr (UnaryArithResHs Not n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exN -> Expr n
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

pack :: (ex :~> a, NicePackedValue a) => ex -> Expr (Packed a)
pack :: forall ex a. (ex :~> a, NicePackedValue a) => ex -> Expr (Packed a)
pack = Expr a -> Expr (Packed a)
forall a1. NicePackedValue a1 => Expr a1 -> Expr (Packed a1)
Pack (Expr a -> Expr (Packed a))
-> (ex -> Expr a) -> ex -> Expr (Packed a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr a
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

unpack :: (NiceUnpackedValue a, exb :~> Packed a) => exb -> Expr (Maybe a)
unpack :: forall a exb.
(NiceUnpackedValue a, exb :~> Packed a) =>
exb -> Expr (Maybe a)
unpack = Expr (Packed a) -> Expr (Maybe a)
forall a1.
NiceUnpackedValue a1 =>
Expr (Packed a1) -> Expr (Maybe a1)
Unpack (Expr (Packed a) -> Expr (Maybe a))
-> (exb -> Expr (Packed a)) -> exb -> Expr (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exb -> Expr (Packed a)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

packRaw :: (ex :~> a, NicePackedValue a) => ex -> Expr ByteString
packRaw :: forall ex a. (ex :~> a, NicePackedValue a) => ex -> Expr ByteString
packRaw = Expr a -> Expr ByteString
forall a1. NicePackedValue a1 => Expr a1 -> Expr ByteString
PackRaw (Expr a -> Expr ByteString)
-> (ex -> Expr a) -> ex -> Expr ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr a
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

unpackRaw :: (NiceUnpackedValue a, exb :~> ByteString) => exb -> Expr (Maybe a)
unpackRaw :: forall a exb.
(NiceUnpackedValue a, exb :~> ByteString) =>
exb -> Expr (Maybe a)
unpackRaw = Expr ByteString -> Expr (Maybe a)
forall a1.
NiceUnpackedValue a1 =>
Expr ByteString -> Expr (Maybe a1)
UnpackRaw (Expr ByteString -> Expr (Maybe a))
-> (exb -> Expr ByteString) -> exb -> Expr (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exb -> Expr ByteString
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

pair :: (ex1 :~> n, ex2 :~> m, KnownValue (n, m)) => ex1 -> ex2 -> Expr (n, m)
pair :: forall ex1 n ex2 m.
(ex1 :~> n, ex2 :~> m, KnownValue (n, m)) =>
ex1 -> ex2 -> Expr (n, m)
pair ex1
a ex2
b = Expr n -> Expr m -> Expr (n, m)
forall n m. KnownValue (n, m) => Expr n -> Expr m -> Expr (n, m)
Pair (ex1 -> Expr (ExprType ex1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr ex1
a) (ex2 -> Expr (ExprType ex2)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr ex2
b)

car, fst :: (op :~> (n, m), KnownValue n) => op -> Expr n
car :: forall op n m. (op :~> (n, m), KnownValue n) => op -> Expr n
car = op -> Expr n
forall op n m. (op :~> (n, m), KnownValue n) => op -> Expr n
fst
fst :: forall op n m. (op :~> (n, m), KnownValue n) => op -> Expr n
fst = Expr (n, m) -> Expr n
forall a m. KnownValue a => Expr (a, m) -> Expr a
Fst (Expr (n, m) -> Expr n) -> (op -> Expr (n, m)) -> op -> Expr n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. op -> Expr (n, m)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

cdr, snd :: (op :~> (n, m), KnownValue m) => op -> Expr m
cdr :: forall op n m. (op :~> (n, m), KnownValue m) => op -> Expr m
cdr = op -> Expr m
forall op n m. (op :~> (n, m), KnownValue m) => op -> Expr m
snd
snd :: forall op n m. (op :~> (n, m), KnownValue m) => op -> Expr m
snd = Expr (n, m) -> Expr m
forall a n. KnownValue a => Expr (n, a) -> Expr a
Snd (Expr (n, m) -> Expr m) -> (op -> Expr (n, m)) -> op -> Expr m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. op -> Expr (n, m)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

some :: (ex :~> t, KnownValue (Maybe t)) => ex -> Expr (Maybe t)
some :: forall ex t.
(ex :~> t, KnownValue (Maybe t)) =>
ex -> Expr (Maybe t)
some = Expr t -> Expr (Maybe t)
forall t. KnownValue (Maybe t) => Expr t -> Expr (Maybe t)
Some (Expr t -> Expr (Maybe t))
-> (ex -> Expr t) -> ex -> Expr (Maybe t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr t
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

none :: KnownValue t => Expr (Maybe t)
none :: forall t. KnownValue t => 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 :: forall ex x y.
(ex :~> x, KnownValue y, KnownValue (Either y x)) =>
ex -> Expr (Either y x)
right = Expr x -> Expr (Either y x)
forall y x.
(KnownValue y, KnownValue (Either y x)) =>
Expr x -> Expr (Either y x)
Right' (Expr x -> Expr (Either y x))
-> (ex -> Expr x) -> ex -> Expr (Either y x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr x
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

left :: (ex :~> y, KnownValue x, KnownValue (Either y x)) => ex -> Expr (Either y x)
left :: forall ex y x.
(ex :~> y, KnownValue x, KnownValue (Either y x)) =>
ex -> Expr (Either y x)
left = Expr y -> Expr (Either y x)
forall x y.
(KnownValue x, KnownValue (Either y x)) =>
Expr y -> Expr (Either y x)
Left' (Expr y -> Expr (Either y x))
-> (ex -> Expr y) -> ex -> Expr (Either y x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr y
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

slice
  :: ( an :~> Natural
     , bn :~> Natural
     , IsSliceExpr ex c
     )
  => (an, bn) -> ex
  -> Expr (Maybe c)
slice :: forall an bn ex c.
(an :~> Natural, bn :~> Natural, IsSliceExpr ex c) =>
(an, bn) -> ex -> Expr (Maybe c)
slice (an
a, bn
b) ex
ex = Expr Natural -> Expr Natural -> Expr c -> Expr (Maybe c)
forall c.
(SliceOpHs c, KnownValue c) =>
Expr Natural -> Expr Natural -> Expr c -> Expr (Maybe c)
Slice (an -> Expr (ExprType an)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr an
a) (bn -> Expr (ExprType bn)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr bn
b) (ex -> Expr (ExprType ex)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr ex
ex)

infixr 6 <>
concat, (<>)
  :: IsConcatExpr exN1 exN2 n
  => exN1 -> exN2
  -> Expr n
concat :: forall exN1 exN2 n.
IsConcatExpr exN1 exN2 n =>
exN1 -> exN2 -> Expr n
concat exN1
a exN2
b = Expr n -> Expr n -> Expr n
forall a.
(ConcatOpHs a, KnownValue a) =>
Expr a -> Expr a -> Expr a
Concat (exN1 -> Expr (ExprType exN1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN1
a) (exN2 -> Expr (ExprType exN2)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN2
b)
<> :: forall exN1 exN2 n.
IsConcatExpr exN1 exN2 n =>
exN1 -> exN2 -> Expr n
(<>) = exN1 -> exN2 -> Expr n
forall exN1 exN2 n.
IsConcatExpr exN1 exN2 n =>
exN1 -> exN2 -> Expr n
concat

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

infixr 5 .:
cons, (.:) :: (ex1 :~> a, ex2 :~> List a) => ex1 -> ex2 -> Expr (List a)
cons :: forall ex1 a ex2.
(ex1 :~> a, ex2 :~> List a) =>
ex1 -> ex2 -> Expr (List a)
cons ex1
el ex2
lst = Expr a -> Expr (List a) -> Expr (List a)
forall a1.
KnownValue (List a1) =>
Expr a1 -> Expr (List a1) -> Expr (List a1)
Cons (ex1 -> Expr (ExprType ex1)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr ex1
el) (ex2 -> Expr (ExprType ex2)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr ex2
lst)
.: :: forall ex1 a ex2.
(ex1 :~> a, ex2 :~> List a) =>
ex1 -> ex2 -> Expr (List a)
(.:) = ex1 -> ex2 -> Expr (List a)
forall ex1 a ex2.
(ex1 :~> a, ex2 :~> List a) =>
ex1 -> ex2 -> Expr (List a)
cons

concatAll :: IsConcatListExpr exN n => exN -> Expr n
concatAll :: forall exN n. IsConcatListExpr exN n => exN -> Expr n
concatAll = Expr (List n) -> Expr n
forall a. (ConcatOpHs a, KnownValue a) => Expr (List a) -> Expr a
Concat' (Expr (List n) -> Expr n)
-> (exN -> Expr (List n)) -> exN -> Expr n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exN -> Expr (List n)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

nil :: KnownValue a => Expr (List a)
nil :: forall a. KnownValue a => Expr (List a)
nil = Expr [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 :: (NiceComparable (UpdOpKeyHs (BigMap k v)),
 KnownValue (BigMap k v)) =>
Expr (BigMap k v)
empty = Expr (BigMap k v)
forall value key.
(KnownValue value, NiceComparable key,
 KnownValue (BigMap key value)) =>
Expr (BigMap key value)
EmptyBigMap

instance KnownValue v => ExprMagma (Map k v) where
  empty :: (NiceComparable (UpdOpKeyHs (Map k v)), KnownValue (Map k v)) =>
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 :: (NiceComparable (UpdOpKeyHs (Set k)), KnownValue (Set k)) =>
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 :: forall ex.
(ex :~> BigMap k v) =>
(exKey, exValue) -> ex -> Expr (BigMap k v)
insert (exKey
k, exValue
v) ex
c = (exKey, Expr (Maybe v)) -> ex -> Expr (BigMap k v)
forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update (exKey
k, exValue -> Expr (Maybe v)
forall ex t.
(ex :~> t, KnownValue (Maybe t)) =>
ex -> Expr (Maybe t)
some exValue
v) ex
c

instance (NiceComparable k, exKey :~> k, exValue :~> v)
    => ExprInsertable (Map k v) (exKey, exValue) where
  insert :: forall ex.
(ex :~> Map k v) =>
(exKey, exValue) -> ex -> Expr (Map k v)
insert (exKey
k, exValue
v) ex
c = (exKey, Expr (Maybe v)) -> ex -> Expr (Map k v)
forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update (exKey
k, exValue -> Expr (Maybe v)
forall ex t.
(ex :~> t, KnownValue (Maybe t)) =>
ex -> Expr (Maybe t)
some exValue
v) ex
c

instance (NiceComparable a, exKey :~> a) => ExprInsertable (Set a) exKey where
  insert :: forall ex. (ex :~> Set a) => exKey -> ex -> Expr (Set a)
insert exKey
k ex
c = (exKey, Bool) -> ex -> Expr (Set a)
forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update (exKey
k, Bool
True) ex
c

-- | 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 :: forall exStruct exKey.
(exStruct :~> BigMap k v, exKey :~> UpdOpKeyHs (BigMap k v)) =>
exKey -> exStruct -> Expr (BigMap k v)
remove exKey
k exStruct
c = (exKey, Expr (Maybe v)) -> exStruct -> Expr (BigMap k v)
forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update (exKey
k, Expr (Maybe v)
forall t. KnownValue t => Expr (Maybe t)
none) exStruct
c

instance (NiceComparable k, KnownValue v) => ExprRemovable (Map k v) where
  remove :: forall exStruct exKey.
(exStruct :~> Map k v, exKey :~> UpdOpKeyHs (Map k v)) =>
exKey -> exStruct -> Expr (Map k v)
remove exKey
k exStruct
c = (exKey, Expr (Maybe v)) -> exStruct -> Expr (Map k v)
forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update (exKey
k, Expr (Maybe v)
forall t. KnownValue t => Expr (Maybe t)
none) exStruct
c

instance NiceComparable a => ExprRemovable (Set a) where
  remove :: forall exStruct exKey.
(exStruct :~> Set a, exKey :~> UpdOpKeyHs (Set a)) =>
exKey -> exStruct -> Expr (Set a)
remove exKey
k exStruct
c = (exKey, Bool) -> exStruct -> Expr (Set a)
forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update (exKey
k, Bool
False) exStruct
c

get
  :: IsGetExpr exKey exMap map
  => exKey -> exMap
  -> Expr (Maybe (GetOpValHs map))
get :: forall exKey exMap map.
IsGetExpr exKey exMap map =>
exKey -> exMap -> Expr (Maybe (GetOpValHs map))
get exKey
k exMap
m = Expr (GetOpKeyHs map) -> Expr map -> Expr (Maybe (GetOpValHs map))
forall c.
(GetOpHs c, KnownValue (Maybe (GetOpValHs c)),
 KnownValue (GetOpValHs c)) =>
Expr (GetOpKeyHs c) -> Expr c -> Expr (Maybe (GetOpValHs c))
Get (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
k) (exMap -> Expr (ExprType exMap)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exMap
m)

update
  :: IsUpdExpr exKey exVal exMap map
  => (exKey, exVal) -> exMap
  -> Expr map
update :: forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap map =>
(exKey, exVal) -> exMap -> Expr map
update (exKey
k, exVal
v) exMap
s = Expr map
-> Expr (UpdOpKeyHs map) -> Expr (UpdOpParamsHs map) -> Expr map
forall a.
(UpdOpHs a, KnownValue a) =>
Expr a -> Expr (UpdOpKeyHs a) -> Expr (UpdOpParamsHs a) -> Expr a
Update (exMap -> Expr (ExprType exMap)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exMap
s) (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
k) (exVal -> Expr (ExprType exVal)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exVal
v)

mem
  :: IsMemExpr exKey exN n
  => exKey -> exN
  -> Expr Bool
mem :: forall exKey exN n.
IsMemExpr exKey exN n =>
exKey -> exN -> Expr Bool
mem exKey
key exN
n = Expr (MemOpKeyHs n) -> Expr n -> Expr Bool
forall c. MemOpHs c => Expr (MemOpKeyHs c) -> Expr c -> Expr Bool
Mem (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
key) (exN -> Expr (ExprType exN)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exN
n)

size
  :: IsSizeExpr exN n
  => exN -> Expr Natural
size :: forall exN n. IsSizeExpr exN n => exN -> Expr Natural
size = Expr n -> Expr Natural
forall c. SizeOpHs c => Expr c -> Expr Natural
Size (Expr n -> Expr Natural) -> (exN -> Expr n) -> exN -> Expr Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exN -> Expr n
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

infixl 8 #:
(#:)
  :: IsGetExpr exKey exMap map
  => exMap -> exKey
  -> Expr (Maybe (GetOpValHs map))
#: :: forall exKey exMap map.
IsGetExpr exKey exMap 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
!: :: forall exKey exVal exMap map.
IsUpdExpr exKey exVal exMap 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
+: :: forall c exParam exStructure.
(ExprInsertable c exParam, exStructure :~> 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
-: :: forall c exStruct exKey.
(ExprRemovable c, exStruct :~> c, exKey :~> UpdOpKeyHs 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
?: :: forall exKey exN n.
IsMemExpr exKey exN n =>
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 :: forall value key.
(KnownValue value, NiceComparable key,
 KnownValue (BigMap key value)) =>
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 :: forall value key.
(KnownValue value, NiceComparable key,
 KnownValue (Map key value)) =>
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 :: forall key.
(NiceComparable key, KnownValue (Set key)) =>
Expr (Set key)
emptySet = Expr (Set key)
forall c.
(ExprMagma c, NiceComparable (UpdOpKeyHs c), KnownValue c) =>
Expr c
empty

----------------------------------------------------------------------------
-- Storages
----------------------------------------------------------------------------

infixr 8 #@
stGet, (#@)
  :: ( StoreHasSubmap store name key value
     , KnownValue value
     , exKey   :~> key
     , exStore :~> store
     )
  => exStore -> (Label name, exKey)
  -> Expr (Maybe value)
stGet :: forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr (Maybe value)
stGet exStore
store (Label name
uName, exKey
key) = Label name -> Expr key -> Expr store -> Expr (Maybe value)
forall store (name :: Symbol) key value.
(StoreHasSubmap store name key value, KnownValue value) =>
Label name -> Expr key -> Expr store -> Expr (Maybe value)
StGet Label name
uName (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
key) (exStore -> Expr (ExprType exStore)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exStore
store)
#@ :: forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr (Maybe value)
(#@) = exStore -> (Label name, exKey) -> Expr (Maybe value)
forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr (Maybe value)
stGet

infixl 8 !@
stUpdate, (!@)
  :: ( StoreHasSubmap store name key value
     , exKey   :~> key
     , exVal   :~> Maybe value
     , exStore :~> store
     )
  => exStore -> (Label name, exKey, exVal)
  -> Expr store
stUpdate :: forall store (name :: Symbol) key value exKey exVal exStore.
(StoreHasSubmap store name key value, exKey :~> key,
 exVal :~> Maybe value, exStore :~> store) =>
exStore -> (Label name, exKey, exVal) -> Expr store
stUpdate exStore
store (Label name
uName, exKey
key, exVal
val) =
  Label name
-> Expr key -> Expr (Maybe value) -> Expr store -> Expr store
forall a (name :: Symbol) key val.
(StoreHasSubmap a name key val, KnownValue a) =>
Label name -> Expr key -> Expr (Maybe val) -> Expr a -> Expr a
StUpdate Label name
uName (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
key) (exVal -> Expr (ExprType exVal)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exVal
val) (exStore -> Expr (ExprType exStore)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exStore
store)
!@ :: forall store (name :: Symbol) key value exKey exVal exStore.
(StoreHasSubmap store name key value, exKey :~> key,
 exVal :~> Maybe value, exStore :~> store) =>
exStore -> (Label name, exKey, exVal) -> Expr store
(!@) = exStore -> (Label name, exKey, exVal) -> Expr store
forall store (name :: Symbol) key value exKey exVal exStore.
(StoreHasSubmap store name key value, exKey :~> key,
 exVal :~> Maybe value, exStore :~> store) =>
exStore -> (Label name, exKey, exVal) -> Expr store
stUpdate

infixr 8 +@
stInsert, (+@)
  :: ( StoreHasSubmap store name key value
     , exKey   :~> key
     , exVal   :~> value
     , exStore :~> store
     )
  => exStore -> (Label name, exKey, exVal)
  -> Expr store
stInsert :: forall store (name :: Symbol) key value exKey exVal exStore.
(StoreHasSubmap store name key value, exKey :~> key,
 exVal :~> value, exStore :~> store) =>
exStore -> (Label name, exKey, exVal) -> Expr store
stInsert exStore
store (Label name
uName, exKey
key, exVal
val) =
  Label name -> Expr key -> Expr value -> Expr store -> Expr store
forall a (name :: Symbol) key value.
(StoreHasSubmap a name key value, KnownValue a) =>
Label name -> Expr key -> Expr value -> Expr a -> Expr a
StInsert Label name
uName (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
key) (exVal -> Expr (ExprType exVal)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exVal
val) (exStore -> Expr (ExprType exStore)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exStore
store)
+@ :: forall store (name :: Symbol) key value exKey exVal exStore.
(StoreHasSubmap store name key value, exKey :~> key,
 exVal :~> value, exStore :~> store) =>
exStore -> (Label name, exKey, exVal) -> Expr store
(+@) = exStore -> (Label name, exKey, exVal) -> Expr store
forall store (name :: Symbol) key value exKey exVal exStore.
(StoreHasSubmap store name key value, exKey :~> key,
 exVal :~> value, exStore :~> store) =>
exStore -> (Label name, exKey, exVal) -> Expr store
stInsert

infixr 8 ++@
stInsertNew, (++@)
  :: ( StoreHasSubmap store name key value
     , Dupable key
     , IsError err
     , Buildable err
     , exKey   :~> key
     , exVal   :~> value
     , exStore :~> store
     )
  => exStore
  -> (Label name, err, exKey, exVal)
  -> Expr store
stInsertNew :: forall store (name :: Symbol) key value err exKey exVal exStore.
(StoreHasSubmap store name key value, Dupable key, IsError err,
 Buildable err, exKey :~> key, exVal :~> value,
 exStore :~> store) =>
exStore -> (Label name, err, exKey, exVal) -> Expr store
stInsertNew exStore
store (Label name
uName, err
err, exKey
key, exVal
val) =
  Label name
-> err -> Expr key -> Expr value -> Expr store -> Expr store
forall a (name :: Symbol) key value err.
(StoreHasSubmap a name key value, KnownValue a, Dupable key,
 IsError err, Buildable err) =>
Label name -> err -> Expr key -> Expr value -> Expr a -> Expr a
StInsertNew Label name
uName err
err (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
key) (exVal -> Expr (ExprType exVal)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exVal
val) (exStore -> Expr (ExprType exStore)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exStore
store)
++@ :: forall store (name :: Symbol) key value err exKey exVal exStore.
(StoreHasSubmap store name key value, Dupable key, IsError err,
 Buildable err, exKey :~> key, exVal :~> value,
 exStore :~> store) =>
exStore -> (Label name, err, exKey, exVal) -> Expr store
(++@) = exStore -> (Label name, err, exKey, exVal) -> Expr store
forall store (name :: Symbol) key value err exKey exVal exStore.
(StoreHasSubmap store name key value, Dupable key, IsError err,
 Buildable err, exKey :~> key, exVal :~> value,
 exStore :~> store) =>
exStore -> (Label name, err, exKey, exVal) -> Expr store
stInsertNew

infixl 8 -@
stDelete, (-@)
  :: ( StoreHasSubmap store name key value
     , KnownValue value
     , exKey   :~> key
     , exStore :~> store
     )
  => exStore -> (Label name, exKey)
  -> Expr store
stDelete :: forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr store
stDelete exStore
store (Label name
uName, exKey
key) = Label name -> Expr key -> Expr store -> Expr store
forall a (name :: Symbol) key val.
(StoreHasSubmap a name key val, KnownValue a, KnownValue val) =>
Label name -> Expr key -> Expr a -> Expr a
StDelete Label name
uName (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
key) (exStore -> Expr (ExprType exStore)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exStore
store)
-@ :: forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr store
(-@) = exStore -> (Label name, exKey) -> Expr store
forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr store
stDelete

infixl 8 ?@
stMem, (?@)
  :: ( StoreHasSubmap store name key value
     , KnownValue value
     , exKey   :~> key
     , exStore :~> store
     )
  => exStore -> (Label name, exKey)
  -> Expr Bool
stMem :: forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr Bool
stMem exStore
store (Label name
uName, exKey
key) = Label name -> Expr key -> Expr store -> Expr Bool
forall store (name :: Symbol) key val.
(StoreHasSubmap store name key val, KnownValue val) =>
Label name -> Expr key -> Expr store -> Expr Bool
StMem Label name
uName (exKey -> Expr (ExprType exKey)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exKey
key) (exStore -> Expr (ExprType exStore)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exStore
store)
?@ :: forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr Bool
(?@) = exStore -> (Label name, exKey) -> Expr Bool
forall store (name :: Symbol) key value exKey exStore.
(StoreHasSubmap store name key value, KnownValue value,
 exKey :~> key, exStore :~> store) =>
exStore -> (Label name, exKey) -> Expr Bool
stMem

----------------------------------------------------------------------------
-- Sum types
----------------------------------------------------------------------------

wrap
  :: ( InstrWrapOneC dt name
     , exField :~> CtorOnlyField name dt
     , KnownValue dt
     )
  => Label name
  -> exField
  -> Expr dt
wrap :: forall dt (name :: Symbol) exField.
(InstrWrapOneC dt name, exField :~> CtorOnlyField name dt,
 KnownValue dt) =>
Label name -> exField -> Expr dt
wrap Label name
l = Label name -> Expr (CtorOnlyField name dt) -> Expr dt
forall a (name :: Symbol).
(InstrWrapOneC a name, KnownValue a) =>
Label name -> Expr (CtorOnlyField name a) -> Expr a
Wrap Label name
l (Expr (CtorOnlyField name dt) -> Expr dt)
-> (exField -> Expr (CtorOnlyField name dt)) -> exField -> Expr dt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exField -> Expr (CtorOnlyField name dt)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

unwrap
  :: ( InstrUnwrapC dt name
     , exDt :~> dt
     , KnownValue (CtorOnlyField name dt)
     )
  => Label name
  -> exDt
  -> Expr (CtorOnlyField name dt)
unwrap :: forall dt (name :: Symbol) exDt.
(InstrUnwrapC dt name, exDt :~> dt,
 KnownValue (CtorOnlyField name dt)) =>
Label name -> exDt -> Expr (CtorOnlyField name dt)
unwrap Label name
l = Label name -> Expr dt -> Expr (CtorOnlyField name dt)
forall dt (name :: Symbol).
(InstrUnwrapC dt name, KnownValue (CtorOnlyField name dt)) =>
Label name -> Expr dt -> Expr (CtorOnlyField name dt)
Unwrap Label name
l (Expr dt -> Expr (CtorOnlyField name dt))
-> (exDt -> Expr dt) -> exDt -> Expr (CtorOnlyField name dt)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exDt -> Expr dt
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

infixl 8 #!
(#!)
  :: (HasField dt name ftype, exDt :~> dt)
  => exDt
  -> Label name
  -> Expr ftype
#! :: forall dt (name :: Symbol) ftype exDt.
(HasField dt name ftype, exDt :~> dt) =>
exDt -> Label name -> Expr ftype
(#!) (exDt -> Expr (ExprType exDt)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr -> (ObjMan ObjectManipulation (ExprType exDt)
fa)) Label name
fName = ObjectManipulation ftype -> Expr ftype
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt -> Label name -> ObjectManipulation ftype
forall dt (fname :: Symbol) a.
HasField dt fname a =>
ObjectManipulation dt -> Label fname -> ObjectManipulation a
ToField ObjectManipulation dt
ObjectManipulation (ExprType exDt)
fa Label name
fName)
(#!) exDt
exDt Label name
fName = ObjectManipulation ftype -> Expr ftype
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt -> Label name -> ObjectManipulation ftype
forall dt (fname :: Symbol) a.
HasField dt fname a =>
ObjectManipulation dt -> Label fname -> ObjectManipulation a
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
!! :: forall dt (name :: Symbol) ftype exDt exFld.
(HasField dt name ftype, exDt :~> dt, exFld :~> ftype) =>
exDt -> (Label name, exFld) -> Expr dt
(!!) (exDt -> Expr (ExprType exDt)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr -> (ObjMan ObjectManipulation (ExprType exDt)
fa)) (Label name
fName, exFld
eFld) = ObjectManipulation dt -> Expr dt
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt
-> Label name -> Expr ftype -> ObjectManipulation dt
forall a (fname :: Symbol) ftype.
HasField a fname ftype =>
ObjectManipulation a
-> Label fname -> Expr ftype -> ObjectManipulation a
SetField ObjectManipulation dt
ObjectManipulation (ExprType exDt)
fa Label name
fName (exFld -> Expr (ExprType exFld)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exFld
eFld))
exDt
dt !! (Label name
fName, exFld
eFld) = ObjectManipulation dt -> Expr dt
forall a. ObjectManipulation a -> Expr a
ObjMan (ObjectManipulation dt
-> Label name -> Expr ftype -> ObjectManipulation dt
forall a (fname :: Symbol) ftype.
HasField a fname ftype =>
ObjectManipulation a
-> Label fname -> Expr ftype -> ObjectManipulation a
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
eFld))

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

name :: (ex :~> t, KnownValue (name :! t)) => Label name -> ex -> Expr (name :! t)
name :: forall ex t (name :: Symbol).
(ex :~> t, KnownValue (name :! t)) =>
Label name -> ex -> Expr (name :! t)
name Label name
lName = Label name -> Expr t -> Expr (name :! t)
forall (name :: Symbol) t.
KnownValue (name :! t) =>
Label name -> Expr t -> Expr (name :! t)
Name Label name
lName (Expr t -> Expr (name :! t))
-> (ex -> Expr t) -> ex -> Expr (name :! t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr t
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

unName :: (ex :~> (name :! t), KnownValue t) => Label name -> ex -> Expr t
unName :: forall ex (name :: Symbol) t.
(ex :~> (name :! t), KnownValue t) =>
Label name -> ex -> Expr t
unName Label name
lName = Label name -> Expr (name :! t) -> Expr t
forall a (name :: Symbol).
KnownValue a =>
Label name -> Expr (name :! a) -> Expr a
UnName Label name
lName (Expr (name :! t) -> Expr t)
-> (ex -> Expr (name :! t)) -> ex -> Expr t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ex -> Expr (name :! t)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

infixl 8 !~
(!~)
  :: (ex :~> t, KnownValue (name :! t))
  => ex -> Label name
  -> Expr (name :! t)
!~ :: forall ex t (name :: Symbol).
(ex :~> t, KnownValue (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).
(ex :~> t, KnownValue (name :! t)) =>
Label name -> ex -> Expr (name :! t)
name

infixl 8 #~
(#~)
  :: (ex :~> (name :! t), KnownValue t)
  => ex -> Label name
  -> Expr t
#~ :: forall ex (name :: Symbol) t.
(ex :~> (name :! t), KnownValue 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.
(ex :~> (name :! t), KnownValue t) =>
Label name -> ex -> Expr t
unName

-- TODO: we should try to make this have a set of 'IsExpr' as input instead of 'Expr'
construct
  :: ( InstrConstructC dt, KnownValue dt
     , RMap (ConstructorFieldTypes dt)
     , RecordToList (ConstructorFieldTypes dt)
     , fields ~ Rec Expr (ConstructorFieldTypes dt)
     , RecFromTuple fields
     )
  => IsoRecTuple fields -> Expr dt
construct :: forall dt fields.
(InstrConstructC dt, KnownValue dt,
 RMap (ConstructorFieldTypes dt),
 RecordToList (ConstructorFieldTypes dt),
 fields ~ Rec Expr (ConstructorFieldTypes dt),
 RecFromTuple fields) =>
IsoRecTuple fields -> Expr dt
construct = Proxy dt -> Rec Expr (ConstructorFieldTypes dt) -> Expr dt
forall a.
(InstrConstructC a, RMap (ConstructorFieldTypes a),
 RecordToList (ConstructorFieldTypes a), KnownValue a) =>
Proxy a -> Rec Expr (ConstructorFieldTypes a) -> Expr a
Construct Proxy dt
forall {k} (t :: k). Proxy t
Proxy(Rec Expr (ConstructorFieldTypes dt) -> Expr dt)
-> (IsoRecTuple (Rec Expr (ConstructorFieldTypes dt))
    -> Rec Expr (ConstructorFieldTypes dt))
-> IsoRecTuple (Rec Expr (ConstructorFieldTypes dt))
-> Expr dt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IsoRecTuple (Rec Expr (ConstructorFieldTypes dt))
-> Rec Expr (ConstructorFieldTypes dt)
forall r. RecFromTuple r => IsoRecTuple r -> r
recFromTuple

constructRec
  :: ( InstrConstructC dt
     , RMap (ConstructorFieldTypes dt)
     , RecordToList (ConstructorFieldTypes dt)
     , KnownValue dt
     )
  => Rec Expr (ConstructorFieldTypes dt)
  -> Expr dt
constructRec :: forall dt.
(InstrConstructC dt, RMap (ConstructorFieldTypes dt),
 RecordToList (ConstructorFieldTypes dt), KnownValue dt) =>
Rec Expr (ConstructorFieldTypes dt) -> Expr dt
constructRec = Proxy dt -> Rec Expr (ConstructorFieldTypes dt) -> Expr dt
forall a.
(InstrConstructC a, RMap (ConstructorFieldTypes a),
 RecordToList (ConstructorFieldTypes a), KnownValue a) =>
Proxy a -> Rec Expr (ConstructorFieldTypes a) -> Expr a
Construct Proxy dt
forall {k} (t :: k). Proxy t
Proxy

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

contract
  :: forall p vd addr exAddr.
     ( NiceParameterFull p
     , NoExplicitDefaultEntrypoint p
     , IsoValue (ContractRef p)
     , ToTAddress p vd addr
     , ToT addr ~ ToT Address
     , exAddr :~> addr
     )
  => exAddr -> Expr (Maybe (ContractRef p))
contract :: forall p vd addr exAddr.
(NiceParameterFull p, NoExplicitDefaultEntrypoint p,
 IsoValue (ContractRef p), ToTAddress p vd addr,
 ToT addr ~ ToT Address, exAddr :~> addr) =>
exAddr -> Expr (Maybe (ContractRef p))
contract = Proxy vd -> Expr addr -> Expr (Maybe (ContractRef p))
forall p vd addr.
(NiceParameterFull p, NoExplicitDefaultEntrypoint p,
 IsoValue (ContractRef p), ToTAddress p vd addr,
 ToT addr ~ ToT Address) =>
Proxy vd -> Expr addr -> Expr (Maybe (ContractRef p))
Contract (forall {t}. Proxy t
forall {k} (t :: k). Proxy t
Proxy @vd) (Expr addr -> Expr (Maybe (ContractRef p)))
-> (exAddr -> Expr addr) -> exAddr -> Expr (Maybe (ContractRef p))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exAddr -> Expr addr
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

self
  :: ( NiceParameterFull p
     , NoExplicitDefaultEntrypoint p
     , IsoValue (ContractRef p)
     , IsNotInView
     )
  => Expr (ContractRef p)
self :: forall p.
(NiceParameterFull p, NoExplicitDefaultEntrypoint p,
 IsoValue (ContractRef p), IsNotInView) =>
Expr (ContractRef p)
self = Expr (ContractRef p)
forall p.
(NiceParameterFull p, NoExplicitDefaultEntrypoint p,
 IsoValue (ContractRef p), IsNotInView) =>
Expr (ContractRef p)
Self

selfAddress :: Expr Address
selfAddress :: Expr Address
selfAddress = Expr Address
SelfAddress

contractAddress :: (exc :~> ContractRef p) => exc -> Expr Address
contractAddress :: forall exc p. (exc :~> ContractRef p) => exc -> Expr Address
contractAddress = Expr (ContractRef p) -> Expr Address
forall p. Expr (ContractRef p) -> Expr Address
ContractAddress (Expr (ContractRef p) -> Expr Address)
-> (exc -> Expr (ContractRef p)) -> exc -> Expr Address
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exc -> Expr (ContractRef p)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

contractCallingUnsafe
  :: ( NiceParameter arg
     , IsoValue (ContractRef arg)
     , exAddr :~> Address
     )
  => EpName -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingUnsafe :: forall arg exAddr.
(NiceParameter arg, IsoValue (ContractRef arg),
 exAddr :~> Address) =>
EpName -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingUnsafe EpName
epName = EpName -> Expr Address -> Expr (Maybe (ContractRef arg))
forall arg.
(NiceParameter arg, IsoValue (ContractRef arg)) =>
EpName -> Expr Address -> Expr (Maybe (ContractRef arg))
ContractCallingUnsafe EpName
epName (Expr Address -> Expr (Maybe (ContractRef arg)))
-> (exAddr -> Expr Address)
-> exAddr
-> Expr (Maybe (ContractRef arg))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exAddr -> Expr Address
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

contractCallingString
  :: ( NiceParameter arg
     , IsoValue (ContractRef arg)
     , exAddr :~> Address
     )
  => MText -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingString :: forall arg exAddr.
(NiceParameter arg, IsoValue (ContractRef arg),
 exAddr :~> Address) =>
MText -> exAddr -> Expr (Maybe (ContractRef arg))
contractCallingString =
    EpName -> exAddr -> Expr (Maybe (ContractRef arg))
forall arg exAddr.
(NiceParameter arg, IsoValue (ContractRef arg),
 exAddr :~> Address) =>
EpName -> exAddr -> 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
. Either String EpName -> EpName
forall a b. (HasCallStack, Buildable a) => Either a b -> b
unsafe (Either String EpName -> EpName)
-> (MText -> Either String EpName) -> MText -> EpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either String EpName
buildEpName
  (Text -> Either String EpName)
-> (MText -> Text) -> MText -> Either String EpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MText -> Text
unMText

runFutureContract
  :: ( NiceParameter p
     , IsoValue (ContractRef p)
     , conExpr :~> FutureContract p
     )
  => conExpr -> Expr (Maybe (ContractRef p))
runFutureContract :: forall p conExpr.
(NiceParameter p, IsoValue (ContractRef p),
 conExpr :~> FutureContract p) =>
conExpr -> Expr (Maybe (ContractRef p))
runFutureContract = Expr (FutureContract p) -> Expr (Maybe (ContractRef p))
forall p.
(NiceParameter p, IsoValue (ContractRef p)) =>
Expr (FutureContract p) -> Expr (Maybe (ContractRef p))
RunFutureContract (Expr (FutureContract p) -> Expr (Maybe (ContractRef p)))
-> (conExpr -> Expr (FutureContract p))
-> conExpr
-> Expr (Maybe (ContractRef p))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. conExpr -> Expr (FutureContract p)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

implicitAccount
  :: (exkh :~> KeyHash)
  => exkh
  -> Expr (ContractRef ())
implicitAccount :: forall exkh. (exkh :~> KeyHash) => exkh -> Expr (ContractRef ())
implicitAccount = Expr KeyHash -> Expr (ContractRef ())
ImplicitAccount (Expr KeyHash -> Expr (ContractRef ()))
-> (exkh -> Expr KeyHash) -> exkh -> Expr (ContractRef ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. exkh -> Expr KeyHash
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

convertEpAddressToContract
  :: ( NiceParameter p
     , IsoValue (ContractRef p)
     , epExpr :~> EpAddress
     )
  => epExpr -> Expr (Maybe (ContractRef p))
convertEpAddressToContract :: forall p epExpr.
(NiceParameter p, IsoValue (ContractRef p),
 epExpr :~> EpAddress) =>
epExpr -> Expr (Maybe (ContractRef p))
convertEpAddressToContract = Expr EpAddress -> Expr (Maybe (ContractRef p))
forall p.
(NiceParameter p, IsoValue (ContractRef p)) =>
Expr EpAddress -> Expr (Maybe (ContractRef p))
ConvertEpAddressToContract (Expr EpAddress -> Expr (Maybe (ContractRef p)))
-> (epExpr -> Expr EpAddress)
-> epExpr
-> Expr (Maybe (ContractRef p))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. epExpr -> Expr EpAddress
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

makeView
  :: ( KnownValue (View_ a r)
     , exa :~> a
     , exCRef :~> ContractRef r
     )
  => exa -> exCRef -> Expr (View_ a r)
makeView :: forall a r exa exCRef.
(KnownValue (View_ a r), exa :~> a, exCRef :~> ContractRef r) =>
exa -> exCRef -> Expr (View_ a r)
makeView exa
a exCRef
cRef = Expr a -> Expr (ContractRef r) -> Expr (View_ a r)
forall a1 r.
KnownValue (View_ a1 r) =>
Expr a1 -> Expr (ContractRef r) -> Expr (View_ a1 r)
MakeView (exa -> Expr (ExprType exa)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exa
a) (exCRef -> Expr (ExprType exCRef)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exCRef
cRef)

makeVoid
  :: ( KnownValue (Void_ a b)
     , exa :~> a
     , exCRef :~> Lambda b b
     )
  => exa -> exCRef -> Expr (Void_ a b)
makeVoid :: forall a b exa exCRef.
(KnownValue (Void_ a b), exa :~> a, exCRef :~> Lambda b b) =>
exa -> exCRef -> Expr (Void_ a b)
makeVoid exa
a exCRef
cRef = Expr a -> Expr (Lambda b b) -> Expr (Void_ a b)
forall a1 b.
KnownValue (Void_ a1 b) =>
Expr a1 -> Expr (Lambda b b) -> Expr (Void_ a1 b)
MakeVoid (exa -> Expr (ExprType exa)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exa
a) (exCRef -> Expr (ExprType exCRef)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr exCRef
cRef)

----------------------------------------------------------------------------
-- 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 :~> TSignature bs
     , hashExpr :~> bs
     , BytesLike bs
     )
  => pkExpr -> sigExpr -> hashExpr
  -> Expr Bool
checkSignature :: forall pkExpr sigExpr bs hashExpr.
(pkExpr :~> PublicKey, sigExpr :~> TSignature bs, hashExpr :~> bs,
 BytesLike bs) =>
pkExpr -> sigExpr -> hashExpr -> Expr Bool
checkSignature pkExpr
pk sigExpr
sig hashExpr
hash = Expr PublicKey -> Expr (TSignature bs) -> Expr bs -> Expr Bool
forall bs.
BytesLike bs =>
Expr PublicKey -> Expr (TSignature bs) -> Expr bs -> Expr Bool
CheckSignature (pkExpr -> Expr (ExprType pkExpr)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr pkExpr
pk) (sigExpr -> Expr (ExprType sigExpr)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr sigExpr
sig) (hashExpr -> Expr (ExprType hashExpr)
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr hashExpr
hash)

sha256 :: (hashExpr :~> bs, BytesLike bs) => hashExpr -> Expr (Hash Sha256 bs)
sha256 :: forall hashExpr bs.
(hashExpr :~> bs, BytesLike bs) =>
hashExpr -> Expr (Hash Sha256 bs)
sha256 = Expr bs -> Expr (Hash Sha256 bs)
forall bs. BytesLike bs => Expr bs -> Expr (Hash Sha256 bs)
Sha256 (Expr bs -> Expr (Hash Sha256 bs))
-> (hashExpr -> Expr bs) -> hashExpr -> Expr (Hash Sha256 bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. hashExpr -> Expr bs
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

sha512 :: (hashExpr :~> bs, BytesLike bs) => hashExpr -> Expr (Hash Sha512 bs)
sha512 :: forall hashExpr bs.
(hashExpr :~> bs, BytesLike bs) =>
hashExpr -> Expr (Hash Sha512 bs)
sha512 = Expr bs -> Expr (Hash Sha512 bs)
forall bs. BytesLike bs => Expr bs -> Expr (Hash Sha512 bs)
Sha512 (Expr bs -> Expr (Hash Sha512 bs))
-> (hashExpr -> Expr bs) -> hashExpr -> Expr (Hash Sha512 bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. hashExpr -> Expr bs
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

blake2b :: (hashExpr :~> bs, BytesLike bs) => hashExpr -> Expr (Hash Blake2b bs)
blake2b :: forall hashExpr bs.
(hashExpr :~> bs, BytesLike bs) =>
hashExpr -> Expr (Hash Blake2b bs)
blake2b = Expr bs -> Expr (Hash Blake2b bs)
forall bs. BytesLike bs => Expr bs -> Expr (Hash Blake2b bs)
Blake2b (Expr bs -> Expr (Hash Blake2b bs))
-> (hashExpr -> Expr bs) -> hashExpr -> Expr (Hash Blake2b bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. hashExpr -> Expr bs
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

sha3 :: (hashExpr :~> bs, BytesLike bs) => hashExpr -> Expr (Hash Sha3 bs)
sha3 :: forall hashExpr bs.
(hashExpr :~> bs, BytesLike bs) =>
hashExpr -> Expr (Hash Sha3 bs)
sha3 = Expr bs -> Expr (Hash Sha3 bs)
forall bs. BytesLike bs => Expr bs -> Expr (Hash Sha3 bs)
Sha3 (Expr bs -> Expr (Hash Sha3 bs))
-> (hashExpr -> Expr bs) -> hashExpr -> Expr (Hash Sha3 bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. hashExpr -> Expr bs
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

keccak :: (hashExpr :~> bs, BytesLike bs) => hashExpr -> Expr (Hash Keccak bs)
keccak :: forall hashExpr bs.
(hashExpr :~> bs, BytesLike bs) =>
hashExpr -> Expr (Hash Keccak bs)
keccak = Expr bs -> Expr (Hash Keccak bs)
forall bs. BytesLike bs => Expr bs -> Expr (Hash Keccak bs)
Keccak (Expr bs -> Expr (Hash Keccak bs))
-> (hashExpr -> Expr bs) -> hashExpr -> Expr (Hash Keccak bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. hashExpr -> Expr bs
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

hashKey :: (keyExpr :~> PublicKey) => keyExpr -> Expr KeyHash
hashKey :: forall keyExpr. (keyExpr :~> PublicKey) => keyExpr -> Expr KeyHash
hashKey = Expr PublicKey -> Expr KeyHash
HashKey (Expr PublicKey -> Expr KeyHash)
-> (keyExpr -> Expr PublicKey) -> keyExpr -> Expr KeyHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. keyExpr -> Expr PublicKey
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

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

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

level :: Expr Natural
level :: Expr Natural
level = Expr Natural
Level

votingPower :: (keyExpr :~> KeyHash) => keyExpr -> Expr Natural
votingPower :: forall keyExpr. (keyExpr :~> KeyHash) => keyExpr -> Expr Natural
votingPower = Expr KeyHash -> Expr Natural
VotingPower (Expr KeyHash -> Expr Natural)
-> (keyExpr -> Expr KeyHash) -> keyExpr -> Expr Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. keyExpr -> Expr KeyHash
forall a. ToExpr a => a -> Expr (ExprType a)
toExpr

totalVotingPower :: Expr Natural
totalVotingPower :: Expr Natural
totalVotingPower = Expr Natural
TotalVotingPower