On 01-Jun-2000, Ketil Malde <[EMAIL PROTECTED]> wrote:
> Fergus Henderson <[EMAIL PROTECTED]> writes:
>
> >> Again, `Positive' would not do, it should be something like
> >> QuotRem_Positive, and so on.
>
> > This is a problem with Haskell, IMHO.
>
> > Mercury allows overloading of constructor names, so in Mercury you
> > could use just `Positive' rather than `QuotRem_Positive'. The type
> > checker will resolve the ambiguity whenever possible.
>
> How will the type inferencer figure out the type if it isn't declared
> explicitly?
Well, the type inferencer considers all possibilities and eliminates
those that are not type-correct. Often only one possibility remains.
If, for example, you write
data Foo = Positive | Negative
data Bar = Sure | Certain | Positive
f Positive = 1
f Negative = -1
g = f Positive
then the type inference can easily infer that `f' has type `Foo -> ...'
rather than `Bar -> ...', since otherwise the second clause of `f'
would not be type-correct. From the type that it infers for `f',
it can then infer that the occurrence of `Positive' in the definition
of `g' has type `Positive'.
In the cases that we were considering, namely mode arguments for
functions in the standard Prelude, the Prelude would contain type
declarations for those functions anyway, so if you write
h = Prelude.func Positive
then the type inference can figure out the type of `Positive'
in the definition of `h' from the type declaration for `Prelude.func'.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.