elm/core

type variables with constraints (number, comparable) make type annotation less useful

CSDUMMI opened this issue · 3 comments

I wrote a function with the following general type annotation:

f : (x -> x) -> (x -> y) -> (x,y) -> List (x,y)

Now I realised, I needed both x and y to be comparable and changed the type annotation thusly:

f : (comparable -> comparable) -> (comparable -> comparable) -> (comparable,comparable) -> List (comparable, comparable)

I find this to be an unnecessary loss of information. Previously I didn't need to write, that my program would handle x and y differently, now nobody has any idea what x and y are, because they are both comparable. Even worse is that now, the two functions I take as an argument seem interchangeable, which they shouldn't be.
Is my problem too particular or has there been any ways of coping with this problem?

You can use suffixes to distinguish between the different comparable types, like comparableX and comparableY.

How would that look as a type annotation and would it still include the comparable constraints?

Just use comparableX and so on in the signature. It will get picked up by the compiler.

Ah, and the issues Are used to track bugs. The best place to get help is the Elm Slack or Discourse.