Hey guys! 🤓

I’m trying to build an UI widget that would accept a label and a set of 
fields and render them as a <fieldset>. Here is how it looks implemented as 
a simple Elm function:

labeledContainer : String -> List (Html Message) -> Html 
MessagelabeledContainer labelText fieldList =    let        label =            
legend [] [ text labelText ]
    in        fieldset [] (label :: fieldList)


and then I use it like this:

view : Model -> Html Messageview model =    labeledContainer "A person section" 
       [ personTypeField initialModel.personType        , 
personTypeSpecificFields initialModel.personType        ]


This is quite common a pattern, so I wanted to extract it as a module so 
that I can reuse it for other widgets. I have tried to just move the 
labeledContainer function in its own file, like this:

module LabeledContainer exposing (..)import Html exposing (..)import 
Html.Attributes exposing (..)labeledContainer : String -> List (Html Message) 
-> Html MessagelabeledContainer labelText fieldList =    let        label =     
       legend [] [ text labelText ]
    in        fieldset [] (label :: fieldList)type Message -- ??? This is 
required as per signature, but I don’t know what should it be    = None


and then import it, but the compiler throws this:

elm-make Main.elm --output=index.html
-- TYPE MISMATCH ----------------------------------------- 
././PersonSection.elm

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

29| view : Model -> Html Message
           ^^^^^^^^^^^^^^^^^^^^^
The type annotation is saying:

    Model -> Html Message

But I am inferring that the definition has this type:

    Model -> Html LabeledContainer.Message

-- TYPE MISMATCH ----------------------------------------- 
././PersonSection.elm

The 2nd argument to function `labeledContainer` is causing a mismatch.

31|     labeledContainer "A person section"
32|>        [ personTypeField initialModel.personType
33|>        , personTypeSpecificFields initialModel.personType
34|>        ]

Function `labeledContainer` is expecting the 2nd argument to be:

    List (Html LabeledContainer.Message)

But it is:

    List (Html Message)

Hint: I always figure out the type of arguments from left to right. If an
argument is acceptable when I check it, I assume it is "correct" in 
subsequent
checks. So the problem may actually be in how previous arguments interact 
with
the 2nd.

Detected errors in 1 module.                                        

🤔 I’m kind of lost and I’m wondering wether this is The Right Approach® to 
reuse the labeledContainer function, and if not, any link/advice on how can 
I find it would be awesome. 👷

Cheers! 🤓

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to