elm-language-server icon indicating copy to clipboard operation
elm-language-server copied to clipboard

Type inference gets confused by aliases

Open miniBill opened this issue 5 years ago • 2 comments

Consider these two modules:

module LocalizedHtml exposing (Html, Language(..), div, text)

import Html


type Language
    = Italian
    | English


type alias Html a =
    Language -> Html.Html a


type alias Attribute a =
    Language -> Html.Attribute a


div : List (Attribute msg) -> List (Html msg) -> Html msg
div attributes children language =
    Html.div (List.map (\a -> a language) attributes) (List.map (\c -> c language) children)


text : String -> String -> Html msg
text en it language =
    Html.text <|
        case language of
            English ->
                en

            Italian ->
                it

and

module Main exposing (main)

import LocalizedHtml exposing (Html, Language(..), div, text)


main =
    div [] [ hello, world ] English


hello : Html msg
hello =
    text "Hello" "Ciao"


world =
    text "World" "Mondo"

notice how Main does not import Html.

Expected Behavior

The type of world is inferred to be Html msg.

Current Behavior

The type of world is inferred to be Language -> Html msg.

Context

I'm wrapping elm-ui to add translations.

miniBill avatar Nov 11 '20 00:11 miniBill

@jmbockhorst can this be closed?

razzeee avatar Dec 12 '20 13:12 razzeee

No, I had to "unfix" this. The type inference is technically correct in this case, but it can maybe be rendered different because of the aliases. It's not a simple solution without adding more to the inference algorithm.

jmbockhorst avatar Dec 12 '20 13:12 jmbockhorst