I see. I tried to report this as a bug, fwiw:
https://bitbucket.org/xnyhps/haskell-unittyped/issue/3/num-i...
Btw, it's weird... I just tried
ack-grep "Num\b"
and I cannot see any instance of Num defined anywhere inside unittyped's srcPS: ok, since I wanted to see exactly what was the problem with unittyped compiling under ghc7.8 I cloned the sources, but I forgot to checkout the actual release... thus running directly from tip was the cause
Installing it directly from hackage solved it, it's embarrassing how I was stunned by this in hindsight
To answer the question of how it is possible, we can start by looking at the types. ":t" is a ghci command to show the type of an expression:
This indicates that "1" can be any type that implements the "Num" typeclass.Next, we want to determine what type "1" takes in the expression "1 meter". We can do this with:
We can see that, in the expression "1 meter", "1" is actually a function. Looking at the source code [1], it seems like this is accomplished in a relativly hacky manner: This works because the "+" being defined here is Prelude.+, not UnitTyped.NoPrelude.+ (which is defined seperatly).[1] https://hackage.haskell.org/package/unittyped-0.1/docs/src/U...