morley-1.20.0: Developer tools for the Michelson Language
Safe HaskellSafe-Inferred
LanguageHaskell2010

Morley.Michelson.Typed.ClassifiedInstr.Internal.WithClassifiedInstr

Description

A more ergonomic way of matching on classified instructions.

Documentation

class WithClassifiedInstr instr where Source #

Associated Types

type WCIConstraint instr (cls' :: InstrClass) :: Constraint Source #

Methods

withClassifiedInstr :: forall t inp out r. ClassifyInstr t => (forall cls. (SingI cls, WCIConstraint instr cls) => Sing (GetClassified cls :: t) -> ClassifiedInstr cls inp out -> r) -> instr inp out -> r Source #

Perform a computation with a classified instruction.

Intended to be used with LambdaCase, e.g.

 isRealInstr :: T.Instr a b -> Bool
 isRealInstr = withClassifiedInstr \case
   SFromMichelson -> True
   SStructural -> False
   SAdditional -> \case
     C_Nop -> False
     C_Ext{} -> True
   SPhantom -> False
 

You can use withClassifiedInstr again to obtain a different classification:

 go = withClassifiedInstr \case
   SFailingNormal -> withClassifiedInstr \case
     SNoChildren -> _
 

If you need to reference the original instruction, consider using & for convenient pointful syntax:

 go i = i & withClassifiedInstr \case
   SFailingNormal -> withClassifiedInstr \case
     SNoChildren -> doStuffWith i
 

Instances

Instances details
WithClassifiedInstr Instr Source # 
Instance details

Defined in Morley.Michelson.Typed.ClassifiedInstr.Internal.WithClassifiedInstr

Associated Types

type WCIConstraint Instr cls' Source #

Methods

withClassifiedInstr :: forall t (inp :: [T]) (out :: [T]) r. ClassifyInstr t => (forall (cls :: InstrClass). (SingI cls, WCIConstraint Instr cls) => Sing (GetClassified cls) -> ClassifiedInstr cls inp out -> r) -> Instr inp out -> r Source #

SingI cls => WithClassifiedInstr (ClassifiedInstr cls) Source # 
Instance details

Defined in Morley.Michelson.Typed.ClassifiedInstr.Internal.WithClassifiedInstr

Associated Types

type WCIConstraint (ClassifiedInstr cls) cls' Source #

Methods

withClassifiedInstr :: forall t (inp :: [T]) (out :: [T]) r. ClassifyInstr t => (forall (cls0 :: InstrClass). (SingI cls0, WCIConstraint (ClassifiedInstr cls) cls0) => Sing (GetClassified cls0) -> ClassifiedInstr cls0 inp out -> r) -> ClassifiedInstr cls inp out -> r Source #