Skip to content

Infinite type error on type that does not appear to be infinite #1614

Open
@evancz

Description

@evancz

Summary and update of @mkolosick's report in #956.

The following code:

import Array exposing (Array)

type alias Focus big small =
    { get : big -> small
    , update : (small -> small) -> big -> big
    }

arrayFocus : Int -> Focus (Array a) a
arrayFocus index =
  Focus (Array.get index) (arrayUpdate index)

arrayUpdate index f array =
  case Array.get index array of
    Just val -> Array.set index (f val) array

Results in the following error with the pre-0.19 compiler:

-- INFINITE TYPE -----------------------------------------------------

I am inferring a weird self-referential type for `arrayFocus`:

139| arrayFocus : Int -> Focus (Array a) a
140| arrayFocus index =
141|   Focus (Array.get index) (arrayUpdate index)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here is my best effort at writing down the type. You will see ∞ for parts of the
type that repeat something already printed out infinitely.

    Focus (Array a) a

Usually staring at the type is not so helpful in these cases, so definitely read
the debugging hints for ideas on how to figure this out:
<https://github.com/elm-lang/elm-compiler/blob/0.19.0/hints/infinite-type.md>

What is going on here? Is this error message legitimate? If so, why does it read so badly? If not, what is going on to cause this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions