Skip to content

Incorrect type inference for Maybe.map2 #47

@jfmengels

Description

@jfmengels

To try the project out, I tried recreating the Maybe.map2 function. The following is my generator code:

map2 : Declaration
map2 =
    Elm.declaration "map2" <|
        Elm.fn3
            ( "fn", Nothing )
            ( "maybeA", Nothing )
            ( "maybeB", Nothing )
            (\fn maybeA maybeB ->
                Elm.Case.maybe maybeA
                    { nothing = Elm.nothing
                    , just =
                        ( "a"
                        , \a ->
                            Elm.Case.maybe maybeB
                                { nothing = Elm.nothing
                                , just =
                                    ( "b"
                                    , \b -> Elm.just (Elm.apply fn [ a, b ])
                                    )
                                }
                        )
                    }
            )

And this is the result:

map2 : (a -> b -> fn) -> maybeA -> maybeB -> Maybe fn
map2 fn maybeA maybeB =
    case maybeA of
        Nothing ->
            Nothing

        Just a_1_0 ->
            case maybeB of
                Nothing ->
                    Nothing

                Just b_2_1_0 ->
                    Just (fn a_1_0 b_2_1_0)

The problem is that the type signature should have been

map2 : (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions