Domanda

I was trying to run the following FParsec code, until by some reason it stopped working:

enter image description here

The error I am getting is

"The value is not a function and cannot be applied."

If I comment out the last line of code (test ns "..") it will not yield an error, though. Any thoughts on how to solve this?


The source code in text form is the following:

open System
open FParsec

let test p str =
    match run p str with
    | Success(result, _, _)   -> printfn "Success: %A" result
    | Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg

type Namespace = { Name : string; Classes : string list; }

let classes : Parser<string list, unit> = 
  many (spaces >>. many1Satisfy isLetter .>> spaces)

let ns =
  pipe2 
    (spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter)
    (spaces >>. skipString "{" >>. classes .>> skipString "}")
    (fun name classes -> { Name = name; Classes = classes } )

test ns "namespace abc { def ghi }"
È stato utile?

Soluzione

Noone could have guessed the answer here. The problem lied with other thing that I had decided to exclude from the post: the very header of my file:

#if INTERACTIVE
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";
#endif

Replacing the ; by ;; will make all errors disappear:

#if INTERACTIVE
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";;
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";;
#endif

Altri suggerimenti

The red underlines clearly show that the compiler thinks that pipe2 is taking four arguments--you should be able to confirm this by added parentheses around the entire test expression like so: (test ns "namespace abs { def ghi })

I'm not sure why though; try putting parentheses around the pipe2 call:

let ns = 
  (pipe2  
     (spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter) 
     (spaces >>. skipString "{" >>. classes .>> skipString "}") 
     (fun name classes -> { Name = name; Classes = classes } ))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top