module Michelson.TypeCheck.TypeCheckedSeq
( TypeCheckedInstr
, TypeCheckedOp(..)
, IllTypedInstr(..)
, TypeCheckedSeq(..)
, tcsEither
, seqToOps
, someInstrToOp
) where
import Michelson.TypeCheck.Error (TCError)
import Michelson.TypeCheck.TypeCheckedOp
(IllTypedInstr(..), TypeCheckedInstr, TypeCheckedOp(..), someInstrToOp)
import Michelson.TypeCheck.Types (SomeInstr(..))
data TypeCheckedSeq inp
= WellTypedSeq (SomeInstr inp)
| MixedSeq (SomeInstr inp) TCError [IllTypedInstr]
| IllTypedSeq TCError [IllTypedInstr]
seqToOps :: TypeCheckedSeq inp -> [TypeCheckedOp]
seqToOps :: TypeCheckedSeq inp -> [TypeCheckedOp]
seqToOps = \case
WellTypedSeq instr :: SomeInstr inp
instr -> [SomeInstr inp -> TypeCheckedOp
forall (inp :: [T]). SomeInstr inp -> TypeCheckedOp
someInstrToOp SomeInstr inp
instr]
MixedSeq instr :: SomeInstr inp
instr _ tail' :: [IllTypedInstr]
tail' -> SomeInstr inp -> TypeCheckedOp
forall (inp :: [T]). SomeInstr inp -> TypeCheckedOp
someInstrToOp SomeInstr inp
instr TypeCheckedOp -> [TypeCheckedOp] -> [TypeCheckedOp]
forall a. a -> [a] -> [a]
: (IllTypedInstr -> TypeCheckedOp)
-> [IllTypedInstr] -> [TypeCheckedOp]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map IllTypedInstr -> TypeCheckedOp
IllTypedOp [IllTypedInstr]
tail'
IllTypedSeq _ tail' :: [IllTypedInstr]
tail' -> (IllTypedInstr -> TypeCheckedOp)
-> [IllTypedInstr] -> [TypeCheckedOp]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map IllTypedInstr -> TypeCheckedOp
IllTypedOp [IllTypedInstr]
tail'
tcsEither
:: ([TypeCheckedOp] -> TCError -> a)
-> (SomeInstr inp -> a)
-> TypeCheckedSeq inp
-> a
tcsEither :: ([TypeCheckedOp] -> TCError -> a)
-> (SomeInstr inp -> a) -> TypeCheckedSeq inp -> a
tcsEither onErr :: [TypeCheckedOp] -> TCError -> a
onErr onInstr :: SomeInstr inp -> a
onInstr v :: TypeCheckedSeq inp
v = case TypeCheckedSeq inp
v of
WellTypedSeq instr :: SomeInstr inp
instr -> SomeInstr inp -> a
onInstr SomeInstr inp
instr
MixedSeq _ err :: TCError
err _ -> [TypeCheckedOp] -> TCError -> a
onErr (TypeCheckedSeq inp -> [TypeCheckedOp]
forall (inp :: [T]). TypeCheckedSeq inp -> [TypeCheckedOp]
seqToOps TypeCheckedSeq inp
v) TCError
err
IllTypedSeq err :: TCError
err _ -> [TypeCheckedOp] -> TCError -> a
onErr (TypeCheckedSeq inp -> [TypeCheckedOp]
forall (inp :: [T]). TypeCheckedSeq inp -> [TypeCheckedOp]
seqToOps TypeCheckedSeq inp
v) TCError
err