On Wed, Dec 19, 2012 at 10:52 AM, Emanuel Koczwara <
poczta at emanuelkoczwara.pl> wrote:
> If so, how are numbers defined? I can use 1 :: Int or 1 :: Integer. Why
> not Value1 :: MyType1 and Value1 :: MyType2?
Numbers are special-cased in the compiler, because they're polymorphic; in
effect, the literal is output as a call to "fromIntegral" or "fromRational"
as appropriate for the type, on some low level internal representation of
the literal. (There is an extension to enable this for strings as well,
but not for other types.) You can't do this with user defined types
because you can't make a constructor a typeclass function.
Note that various things, in particular pattern matching, rely on
constructor names unambiguously identifying types. (Again, numeric
literals are a special case; patterns involving them actually get rewritten
into guards. If you want to know the gory details, they're documented in
the Haskell Language Report.)