Skip to content

Instantly share code, notes, and snippets.

@MarkyMarkMcDonald
Last active September 21, 2016 17:07
Show Gist options
  • Save MarkyMarkMcDonald/7393b19b339a0394edd090ee61d547ad to your computer and use it in GitHub Desktop.
Save MarkyMarkMcDonald/7393b19b339a0394edd090ee61d547ad to your computer and use it in GitHub Desktop.
Exposing list of attributes to be iterated over by validation check. See https://github.com/MarkyMarkMcDonald/elm-architecture-tutorial/commit/ede42b04414df3365dd6d7673dca9b6a6a32ab61?w=1 for full context
type Shape = Diamond | Oval | Squiggle
type Number = One | Two | Three
type Color = Red | Green | Blue
type Attribute = Color | Shape | Number
type alias Model = {
shape: Shape,
number: Number,
color: Color
}
attributes : List (Model -> Attribute)
attributes = [.color, .shape, .number]
@MarkyMarkMcDonald
Copy link
Author

We get this compiler error:

==================================== ERRORS ====================================

-- TYPE MISMATCH ------------------------------------------------- ./../Card.elm

The type annotation for `attributes` does not match its definition.

14| attributes : List (Model -> Attribute)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
The type annotation is saying:

    List ({ ..., number : Number, shape : Shape } -> Attribute)

But I am inferring that the definition has this type:

    List ({ ..., number : Color, shape : Color } -> Color)

Detected errors in 1 module.
Compilation failed for Main.elm

@MarkyMarkMcDonald
Copy link
Author

Working final solution:

type alias Model =
    { shape: Shape
    , number: Number
    , color: Color
    }

attributes : List (Model -> Attribute)
attributes = [\x -> ColorAtt x.color, \x -> ShapeAtt x.shape, \x -> NumberAtt x.number]

type Attribute
  = ColorAtt Color
  | ShapeAtt Shape
  | NumberAtt Number

type Color = Red | Green | Blue
type Shape = Diamond | Oval | Squiggle
type Number = One | Two | Three

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment