`typeof` syntactic sugar

Could you please give a short example for this problem.

I don’t think I can. And upon further thought, I believe I’m just wrong about this. Theoretically, typeof is just a language feature for nameless type aliases that correspond to some top-level identifier’s type signature. If the only difference here is that they are unnamed and their definition is tied to an existing identifier’s type signature rather than the one the user writes in named type aliases, then it should work the same as type aliases.

For context, I was thinking of what happened in Unbiasing the Semigroup instance for Map. But, comparing this situation to that one is wrong. That problem only arose because 'a change an instance implementation has subtle effects on existing code and the compiler doesn’t error. So, we needed a public post to raise awareness of the problem given how heavily it’s used. I thought that this proposed feature could suffer from a similar situation, but I think it’s more apt to describe it as being another potential avenue in which the above problem can occur.

But that being said, can typeof reference the identifier in which it’s used?

f :: typeof "f"
f x = x

I would assume not. However, one could argue that we could use the inferred type of f here. But what about when it references something else that’s part of a mutually-recursive group?

isEven :: typeof "isOdd"
isEven x
  | x == 0 = true
  | otherwise = not $ isOdd x

isOdd :: typeof "isEven"
isOdd x = isEven (x - 1)

Again, I assume not, but perhaps we could use the inferred type here?

1 Like