[Haskell-cafe] Re: Overloading functions based on arguments?

Jonathan Cast jonathanccast at fastmail.fm
Fri Feb 13 16:11:49 EST 2009


On Fri, 2009-02-13 at 21:57 +0100, Daniel Fischer wrote:
> Am Freitag, 13. Februar 2009 21:08 schrieb Jonathan Cast:
> > On Fri, 2009-02-13 at 12:15 -0700, John A. De Goes wrote:
> > > On Feb 13, 2009, at 12:07 PM, Jonathan Cast wrote:
> > > > Exactly!  But if it fails, why on earth should any other use of map in
> > > > the module succeed?
> > >
> > > Because more information is known about other usages of map. Such is
> > > the nature of type inference.
> >
> > No it's not.  Type inference -- in Haskell --- means --- by definition!
> > --- looking up the principle type of each sub-term, specializing it
> > based on its use, and then generalizing to find the principle type of
> > the overall term.  Adding information can cause type inference to fail,
> > but --- in Haskell as it exists --- it cannot cause type inference to
> > succeed.
> 
> I'm not sure about the finer distinctions between type inference and type 
> checking as performed by Haskell implementations when compiling a module, but 
> what about polymorphic recursion, where adding information via a type 
> signature can be necessary to make the compilation succeed?

Um, sort of.  Adding --- or relaxing --- a type signature on a function
you *call* can make typing succeed when it would have failed.  But take
the recursion out of polymorphic recursion and it does become
problematic, yes.  For much the same reason the monomorphism restriction
is problematic, actually.

> Not what this thread is about, though.
> 
> >  Which is good!
> 
> Why is it good?

The compiler should fail when you tell it two mutually contradictory
things, and only when you tell it two mutually contradictory things.
Adding information cannot remove a contradiction from the information
set available to the compiler.  Therefore it should not stop the
compiler from failing.

And that is all I will say on this subject.

jcc




More information about the Haskell-Cafe mailing list