The definition of `validate` does not match its type annotation

Hi, I’m quite confused about something that will most probably result in a big AHA! and that I suddenly broke without understanding why…
I’m validating a form with elm-form, and implemented the validate function as in the examples: https://github.com/etaque/elm-form/blob/master/example/src/Model.elm
What I did is even simpler:

validate : Validation CustomError User
validate =
  succeed User
    |> andMap (field "user[kind]" validateKind)

validateKind : Validation CustomError Kind
validateKind =
  customValidation
    string
    (\s ->
      case s of
        "creator" ->
          Ok CreatorKind
        "supplier" ->
          Ok SupplierKind
        _ ->
          Err (customError InvalidKind)
    )

The error I get is

The type annotation for `validate` says it is a:
  Validation CustomError (User)
But the definition (shown above) is a:
  Validation CustomError (Role -> User)

I can see what validateKind returns of course, what I don’t get is what is the difference with the example above? If you look at validateSuperpower it’s basically the same code.
Can anybody share a hint?

Thanks in advance,
ngw

What’s the definition of the User type?

Without seeing the User type it’s a bit hard to make a guess, but it seems like User takes two parameters, not just one.
Assuming you have something like: type alias User = { kind: Kind, role: Role }
then validate is missing the field role.

So it should probably be:

validate : Validation CustomError User
validate =
  succeed User
    |> andMap (field "user[kind]" validateKind)
    |> andMap (field "user[role]" validateRole)

Or a constant field or whatever you need for the “role” field.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.