I recently learned that Nim has pattern matching through the `fusion/matching` 
library. I was trying to make this OCaml example in Nim: 
    
    
    let rec sum = function
    | [] -> 0
    | head :: tail -> head + (sum tail)
    
    
    Run

This is what I came up with: 
    
    
    import fusion/matching
    {.experimental: "caseStmtMacros".}
    
    func sum(arr: openarray[int]): int =
      case arr:
        of []:
          0
        of [@head, all @tail]:
          head + (sum tail)
    
    echo (sum [1, 2, 3, 4])
    
    
    Run

However, I get a compile error: 
    
    
    /home/rainbow/test.nim(5, 3) template/generic instantiation of `match` from 
here
    /home/rainbow/.nimble/pkgs/fusion-1.0/fusion/matching.nim(2339, 13) Error: 
invalid type: 'openArray[int]' for let
    
    
    Run

Is this just a bug or am I doing something wrong?

Reply via email to