[Haskell-cafe] Newbie question
Bulat Ziganshin
bulat.ziganshin at gmail.com
Mon Jan 21 14:39:25 EST 2008
Hello Alexander,
Monday, January 21, 2008, 7:36:18 PM, you wrote:
> How does caller choose which particular instance of Num they want?
> In object-oriented language If function return type is an interface
> it means that it can return any implementation of this interface,
> but caller can't choose which particular inplementation they want.
but type class isn't an interface! it's just like interface in one
concrete area - it includes method specifications, but not includes
data fields
the type that should ìó returned by function is passed by means of
so-called dictionary and which type should be returned is defined by
type inference process. for example
main = print (length [] + f 1)
here f should return Int because length return Int and you can't add
values of different types (without explicit type conversion). you
should also read something about two-way type inference but i don't
know any good source
please note that in modern OOP languages (latest C# versions, C++ 0x)
support for *one-way* type inference was only added, i.e. they only can
deduce type of expression from types of operands, while Haskell
deduces types in both directions
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list