opa:stringmap编译错误和HttpRequest.Generic.get_form_data(HttpRequest.request x)

时间:2012-07-09 10:05:52

标签: compilation opa

我正在尝试编译以下代码,但它是falis:

import stdlib.core.map

function f()
{
        stringmap(string) myM = StringMap.add("rabbit", "horse", StringMap_empty)
        string rabbit= myM["rabbit"]
}

为什么?我对此代码与我之前发布的opa(0.9。*)一起使用感到非常满意。

如何访问存储在StringMap中的数据?在我的代码中,我想通过

访问数据返回
HttpRequest.Generic.get_form_data(HttpRequest.request x).

由于

1 个答案:

答案 0 :(得分:2)

没有您的代码无法使用任何以前版本的Opa。我们已经在您在此处打开的先前主题中讨论了Opa和StringMap的某些方面:Opa : howo to manipulate stringmap (and other map)

总结:

  • Opa是一种函数式编程语言,您的函数f不能以rabbit = v之类的绑定结束。
  • 没有myM["rabbit"]语法,您必须在案例中使用StringMap.get

这是一个有效的代码:

import stdlib.core.map

function f()
{
        stringmap(string) myM = StringMap.add("rabbit", "horse", StringMap_empty)
        match (StringMap.get("rabbit", myM)) {
        case {none}: "not found"
        case {some:value}: value
        }
}