Elm Bandwagon exercise - don't understand error message

Hi All,

This is the error I’m getting:

elm-test-rs 3.0.0 for elm 0.19.1
--------------------------------

-- TYPE MISMATCH --------------------------------- /tmp/solution/tests/Tests.elm

This function cannot handle the argument sent through the (|>) pipe:

88|                     { name = "", coach = Coach "" True, stats = Stats 1 0, someOtherField = "" }
89|                         |> rootForTeam
                               ^^^^^^^^^^^
The argument is:

    { coach : Int -> Coach
    , name : String
    , someOtherField : String
    , stats : Stats
    }

But (|>) is piping it to a function that expects:

    { coach : Int -> Coach
    , name : String
    , someOtherField : String
    , stats : { a | false : comparable, losses : Int, wins : comparable }
    }

Here’s my attempt:

module Bandwagoner exposing (..)

-- TODO: please define a type alias for the 'Coach' record
type alias Coach = 
    { name: String
    , formerPlayer: Bool
    , losses: Int
    }
-- TODO: please define the 'Stats' record

type alias Stats =   
    { 
     wins: Int
    , losses: Int
    }
-- TODO: please define the 'Team' record

type alias Team = 
    { name: String
    , coach: Coach
    , stats: Stats
    }


replaceCoach newCoach team =
    -- Debug.todo "Please implement this function"
    {team | coach = newCoach}

createTeam name stats coach =
   -- Debug.todo "Please implement this function"
    Team name coach stats


-- TODO: use an extensible record to accept any record that has a `stats: Stats` field
-- TODO: use pattern matching in the function parameter to get the `stats` field from the record


rootForTeam team =
    --Debug.todo "Please implement this function, try to pattern match in the function parameter"
    team.stats.wins > team.stats.false

any hints?

Thanks

In your Coach type alias, a coach has to have a “losses” property. Is that true in the tests?

1 Like

Note that your rootForTeam function takes a team explicitly, not “any record that has a stats: Stats field”

1 Like

Hey glennj, thanks for replying. Sorry, I don’t really understand what you’re asking. My Coach type alias does have an losses property, however I’m not sure how to tell if its true in the tests, afaik i don’t have access to the tests.

thanks again, i’m not quite sure what I can do with this? Its the tests passing the team to rootForTeam, not my code, so im not sure how I can make sure the tests are passing the correct thing? Or am I missing your point?

Ok, i’ve fixed my issues; I had misread instructions and defined Coach incorrectly. glennj, really appreciate you engaging.

1 Like

OK! Now i get it! Thanks for this.

Apologies, I only just got to this, but it looks like everything has worked out ok …

1 Like