Search code examples
compilationopa

opa : stringmap compilation error and HttpRequest.Generic.get_form_data(HttpRequest.request x)


I'm trying to compile the following code, but it falis :

import stdlib.core.map

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

Why is that ? I have the feelling that this code was working with my previous release of opa (0.9.*).

How can I access to data stored in a StringMap ? In my code, I want to access the data return by a

HttpRequest.Generic.get_form_data(HttpRequest.request x).

Thanks


Solution

  • No your code can't have worked on any previous version of Opa. We already discuss about some aspects of Opa and StringMap in a previous thread you opened here: Opa : howo to manipulate stringmap (and other map)

    In summary:

    • Opa is a functional programming language, your function f can't end with a binding like rabbit = v.
    • there is not myM["rabbit"] syntax, you have to use StringMap.get in your case.

    Here is a working code:

    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
            }
    }