[nem-en] This sounds like a bug.

Maurizio Colucci seguso.forever at tin.it
Thu Jul 15 07:22:45 CEST 2004


On Wednesday 14 July 2004 12:22, Michal Moskal wrote:
> On Tue, Jul 13, 2004 at 04:37:27PM -0700, Maurizio Colucci wrote:
> > Hello again.
> >
> > Nemerle doesn't seem to be able to infer the type of "o" in the line
> > marked (***). OTOH, if I specify the type (Obj), it compiles. But the
> > type could be inferred by looking at the type of ForAll...
> >
> >
> > using Nemerle.Collections;
> >
> > [Record]
> > class Obj{
> >   public name: string;
> > }
> >
> > module Logic{
> >
> > public they_are_all_called_j( selected_objects : list<Obj>) : bool{
> >     List.ForAll( selected_objects,
> >                   fun (o ) { o.name == "j"}); // ERROR HERE (***)
> > }
> >
> > } // module Logic
>
> Unfortunately type inference works bottom-up. That is the type of lambda
> must be known before the ForAll is typed. We have considered having
> certain backtracking strategies 

Thanks for the reply.

There are two things I don't understand:

1) It seems to me the bottom-up approach should work in this case, because 
there is only one class with a member called "name". Starting from the 
inside, we read o.name, and we can immediately infer that "o" is of type 
"Obj", since Obj is the _only_ class that provides a member called "name".

2) Even if there were another class with a member called "name", I still don't 
see why you need a backtracking approach. It seems to me a bottom-up approach 
should still work. Suppose you have three classes with a member called 
"name":

[Record]
class Obj{
  public name: string;
}

[Record]
class Verb{
  public name: string;
}

[Record]
class Man{
  public name: int;
}

module Logic{
 public they_are_all_called_j( selected_objects : list<Obj>) : bool{
    List.ForAll( selected_objects,
                  fun (o ) { o.name == "j"}); 
}
}

Suppose the type inference engine doesn't use backtracking, but a simple 
bottom-up approach. Starting from the inside:

*  you read o.name. You deduce that the type of "o" is one of {Obj, Verb,Man}.

* you read o.name == "j". You narrow down the possibilities to {Obj, Verb}.

* you read fun(o){o.name == "j"}. You deduce the type of the lambda to be one 
of {Obj->bool, Verb->bool}

* you read  List.ForAll( selected_objects, fun (o ) { o.name == "j"}); Now you 
can finally narrow down the type of the lambda to {Obj->bool}, and as a 
consequence the type of "o" is "Obj".

All without backtracking. So where is the need for backtracking?

Thanks a lot for the chat,

Maurizio



More information about the devel-en mailing list