I was playing around with hugs today and got stuck at a very simple question:
λ 1 1
:: (Num a, Num (a -> t)) => t
What would that type be? I am having trouble to read this.
And if it has a type, why? I would guess that the expression 1 1 is ill-formed and thus type-checking fails, which is supported by the Haskell compiler.
No it is not ill-formed. The type is strange and there probably cannot be any meaningful values for which it makes sense but it's still allowed.
Keep in mind that literals are overloaded.
1is not an integer. It's anything of typeNum. Functions are not excluded from this. There is no rule sayinga -> tcannot be " a number" (i.e. an instance ofNum).For example you could have an
instancedeclaration like:now
1 1would simply be equalundefined. Not very useful but still valid.You can have useful definitions of
Numfor functions. For example, from the wikiWith this you can write things like:
where
fandgare functions returning numbers.Using the above instance declaration
1 2would be equal to1. Basically a literal used as a function with the above instance is equal toconst <that-literal>.