Is there an idiomatic way to import record fields into the scope of a choice?

For example

data Foo = Foo
  with
    a : Int
    b : Int
  deriving (Eq, Show)

template Bar
  with
    p : Party
    f : Foo
  where
    signatory p 
    choice DoSomething : () 
      controller p 
      do 
        let (a,b) = (f.a, f.b)
        let c = a + b
        pure ()
    

In the choice body, is there an idiomatic way to import a and b instead of let (a,b) = (f.a, f.b)?

1 Like

Yes, you can write let Foo{..} = f, where Foo is the name of the record type. This is an extension to let Foo{a, b} = f syntax, which you may prefer in some situations to skip variables or be slightly more explicit.

This and some other record dismantling tips can be found in this tutorial.

edit: I genuinely didn’t notice that your record type was also called Foo

2 Likes