Daml Finance interfaces

Trying to grasp the concepts of Daml interfaces and its usage in Daml Finance.
One of the things I noticed that for some interfaces, the View type exposes data that is only used by the implementation, not the interface. I understand anyone fetching that interface contract would get access to the data as well, but in some cases I am confused on whether that is desired.

To give a concrete example, please look at the interface NumericObservable and an implementation Observation. View contains observations, being a Map Time Decimal, but it also defines a non-consuming choice Observe, which seems to contain the logic of observing those observations at some time t. Now what would be the rationale to expose the observations in the view in this case?

1 Like

Hi @eriktim,

Thanks for your question.

A rationale for exposing data in the view is for e.g. displaying purposes in a template-agnostic UI. Your UI would work only against the interface type rather than the concrete template type.

In the specific case of NumericObservable, however, it is indeed undesirable to expose the observations in the view, as that would prevent us from defining additional observation templates such as the below. We will rectify this in an upcoming Daml Finance version.

Thanks,
Matteo

-- | Observe 1.0 if a credit event has happened, 0.0 otherwise
template CreditEventObservation
  with
    provider : Party
      -- ^ The reference data provider.
    id : Id
      -- ^ A textual identifier.
    creditEventTime : Optional Time
      -- ^ Identifies when a credit event has happened.
    observers : PartiesMap
      -- ^ Observers.
  where
    signatory provider
    observer Disclosure.flattenObservers observers

    interface instance NumericObservable.I for CreditEventObservation where
      observe t =
        case creditEventTime of
          Some s | t >= s -> pure 1.0
          _ -> pure 0.0

1 Like

Ah in that sense the name View fits nicely as well :slightly_smiling_face:
Thanks for the clear explanation, @Matteo_Limberto!