[Haskell-cafe] a bunch of newbie questions

Bulat Ziganshin bulat.ziganshin at gmail.com
Fri Aug 4 10:38:32 EDT 2006


Hello Mark,

Friday, August 4, 2006, 3:03:54 PM, you wrote:

> I've always been a little surprised when this doesn't happen more widely
> for things other than instances. For instance, when IntMap.size,
> Map.size and Set.size (or whatever) are all in scope as "size", it
> should be fairly obvious what (size x) is about once we've inferred, for
> other reasons, that x is an IntMap. Similarly with records, if we had

this is called ad-hoc polymorphism which is not supported by Haskell.
instead Haskell supports parametric polymorphism via type classes.
i'm not a language lawyer ;)  but thinks that difference between C++
which supports former and Haskell that supports later is the following:
C++ can infer only result type based on arguments type while Haskell
can infer in _both_ directions. i can imagine C++ type inferring
algorithm, with a little imagination i even can think about Haskell's
algorithm :)  but two-way type inferring together with ad-hoc
polymorphism make me a little nervous :)  how about, for example, two
ad-hoc-polymorphic functions: f (g x)? or dozens of such calls
enclosed? how error messages should be generated: "it may be Int::f
with Char::g or Char::f with Bool::g or ... or ... or ..." ? one more
cause is that Haskell was defined by scientists, not practical
programmers, and scientists prefer to use more systematic ways to do
the same things

nevertheless, there is no principal differences. in many cases you can
define type classes, include your ad-hoc polymorphic functions into
these classes and sleep easy. in particular, as Brian already said,
there is a proposal to use automatically generated type classes for
record fields


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list