1

伙计们,这段代码抛出了一个错误

daml 1.2

module PaidService where

template Service
  with
    provider : Party
    beneficiary : Party
    description : Text
    cost : Decimal
    currency : Text
  where
    signatory provider,beneficiary

    controller beneficiary can
      Transer   : ContractId Service
        with nextbeneficiary : Party
        do
          create this with beneficiary = nextbeneficiary


test_1 = scenario do
  beth <- getParty "beth"
  manish <- getParty "manish"
  harsha <- getParty "harsha"

  cid <- manish submit do
    create Service 
      with
        provider = manish
        beneficiary = manish
        description = "Yay"
        cost = 1000.00
        currency = "USD"

{ “资源”:“/home/Daml/learning/hackathon/daml/PaidService.daml”,“所有者”:“_generated_diagnostic_collection_name_#0”,“严重性”:8,“消息”:“/home//Daml/learning /hackathon/daml/PaidService.daml:27:3: 错误:\n 'do' 块中的最后一条语句必须是表达式\n cid <- manish\n submit\n do create\n Service\n {provider = manish, 受益人 = manish, description = \"Yay\",\n cost = 1000.00, currency = \"USD\"}", "source": "typecheck", "startLineNumber": 27, "startColumn": 3 , "endLineNumber": 34, "endColumn": 25 }

为什么会这样?

4

1 回答 1

2

-block 中的最后一行do不能是a <- action. 相反,它必须是您的示例f a中的类型表达式。f = Scenario整个do-block 也将是 type Scenario a。有两种方法可以修复您的示例。

  1. 在末尾添加另一行pure ()pure允许您将任意值嵌入到 -blocka的上下文中do(从技术上讲,它不限于do-blocks,但我不会在这里讨论)所以在这里它允许您嵌入()Scenario上下文中,为您提供 type 的值Scenario ()
  2. 改变
cid <- manish `submit` …

进入

manish `submit` …

在您的示例中,这将导致do-block 具有 type Scenario (ContractId Service)

1 和 2 的主要区别在于 in 1test_1有 typeScenario ()而 in 2test_1有 type Scenario (ContractId Service)。对于您的示例,这种差异并不重要,因为您没有提到test_1任何地方,因此两种解决方案都是合理的。

于 2019-10-06T07:20:28.803 回答