Copied F# code from one module to another and it broke

43 views Asked by At

I ran "dotnet new giraffe."

Then I tried moving the Views module into a Views.fs file. The same code that compiled without error in Program.fs now has an error message in Views.fs:

GiraffeApp/Views.fs(9,20): error FS0003: This value is not a function and cannot be applied. 

It happens at _rel in this function:

let layout (content: XmlNode list) =
    html [] [
        head [] [
            title []  [ encodedText "GiraffeApp" ]
            link [ _rel  "stylesheet"
                    _type "text/css"
                    _href "/main.css" ]
        ]
        body [] content
    ]

Full code change is here: https://github.com/surferjeff/blazor-compared/commit/d6f76bfacf1853d1561b8533666fab24b0f89f3f

The error message is telling me _rel is not a function. Ok, but I don't know what _rel is. I searched the Giraffe repo for _rel and found no instances of that string in the code. I don't understand why it expects _rel to be a function in this context but not when the code was in Program.cs.

1

There are 1 answers

1
Brian Berns On BEST ANSWER

The problem is with your whitespace. By indenting _type under _rel you've made the compiler think that you're invoking a function. Instead of this:

            link [ _rel  "stylesheet"
                    _type "text/css"       // <- incorrect indentation
                    _href "/main.css" ]    // <- incorrect indentation

You want this:

            link [ _rel  "stylesheet"
                   _type "text/css"
                   _href "/main.css" ]