How to lift a type using inline syntax

Hi All,

I’m trying to find a way to lift a type within an Html option, as per these failing expermients:

        notes : Trait -> Html Message
        notes trait =
            Textfield.view
                Mdc
                (trait.id ++ "-note")
                model.mdc
                ([ Textfield.dense
                 , Textfield.fullwidth
                 , Textfield.placeholder "describe here"
                 , Textfield.textarea
                 , Textfield.rows 5
                 , Textfield.cols 40
                 , EditNote <| Options.onInput trait.tagNote                    -- experiment 1 / fails
                 , Options.onInput (EditNote <| trait.tagNote)                  -- experiment 2 / fails
                 ]
                    ++ ( Html.map EditNote [ Options.onInput trait.tagNote ] )  -- experiment 3 / fails
                )

The module declares these relevant types:

type Message
    = Mdc (Material.Msg Message)
    | EditNote NoteControl

type NoteControl
    = NoteTrackable String
    | NoteMeasurable String

Note that type Mdc is a top level (Message) type given as a Textfield.view argument.

Does there exist a syntax to lift the NoteControl type (denoted by trait.tagNote) into a Message type, inline within the Html option list above, or is it not possible?

I’m aware of alternative code structures (which are far more verbose) to handle this, but I’m looking for an inline syntax solution.

Thanks.

Im not sure I fully grasp what you are asking. But EditNote is a way to turn a NoteControl into a Message. Thats “lifting” as I understand it. The type of EditNote is NoteControl -> Message. I feel like this is hard to express in english. I mean to point out that this is valid code:

liftNoteControlIntoMessage : NoteControl -> Message
liftNoteControlIntoMessage =
    EditNote

You have actually two functions you can use:

Html.map : (a -> msg) -> Html a -> Html msg
Html.Attributes.map : (a -> msg) -> Attribute a -> Attribute msg

I’m not sure what is the type of your list elements and what you mean by “inline” but I guess you could do something like:

notes trait =
    Html.map EditNote <|
        Textfield.view ...

Thank you!!

I wasn’t aware Html.Attributes.map existed - that’s what I wanted.

Despite what they say, ignorance is not bliss

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