Elm error: I am looking for one of the following things: "'"

786 views Asked by At

I'm getting a compile error:

I am looking for one of the following things:

 "'"
 "."
 a pattern
 an equals sign '='
 more letters in this name
 whitespace

Is it an incomplete type or is the function bad? Capitalized first letter? I have tried building the file block by block and I still get the error as soon as I add the method. If I remove the function type annotation, I get an error on the function definition. I'm clearly misunderstanding a basic concept here

module Test exposing (Test, TestRoot, TestId, GetContainedTests)

type  TestId = String

type alias Test =
    { id : TestId
    , containerId : TestId
    , title : String
    , children : List Test
    }    

type alias TestRoot =
    { id : TestId
    , title : String
    , children : List Test
}   

GetContainedTests: Test -> List Test                    -- error here I am looking for one of the following things: "'"     "."     a pattern     an equals sign '='     more letters in this name     whitespace
GetContainedTests item = 
    let
        result : List Test
        result = item.children
            -- if I comment out the GetContainedTests type annotation, I get an error on the ".map" below: I am looking for one of the following things:     an upper case name

        List.map {\childItem -> List.append result GetContainedTests childItem} item.children
    in
        result

Note: I'm not asking for help with the function (although I welcome it). I'm trying to get past the compiler error

1

There are 1 answers

3
Chad Gilbert On BEST ANSWER

The specific error you mention is because you are trying to use a capital letter as the first character of your function GetContainedTests. In Elm, all functions must start with a lowercase letter. Only types, type aliases, type constructors, and module names can (must) start with an uppercase letter.

A few other things that you'll get compile errors about:

  1. The first argument in List.map should be enclosed in parentheses, not curly braces.

You will get a compile error about defining a recursive type alias. This is because your Test alias references itself. For more information on what the problem is, you can read up on the information in the link provided in the error message. The compiler also recommends making Test a type rather than an alias, like so:

type Test
    = Test
        { id : TestId
        , containerId : TestId
        , title : String
        , children : List Test
        }