[Nickle] Funny situation

Barton C Massey bart at cs.pdx.edu
Sat Jun 28 15:31:36 PDT 2003


Thanks much!  I'm not very happy with the semantics here,
but at least I'm a bit untangled.  The problem with option b
(move the union) is that it doesn't really work right with
imperative stuff.  I'll think about the datatyping some
more, and we'll chat.  Probably I'll end up exposing elem or
something.
	
	Bart

In message <E19WKRX-0001tN-00 at localhost> you wrote:
> 
> Around 0 o'clock on Jun 28, Bart Massey wrote:
> 
> > What am I doing wrong here?  Or is this a Nickle bug?
> 
> Recall that reference types are just syntactic sugar for pointer types:
> 
> 
>   ...
>       public typedef &elem list;
>   ...
>       public list empty = &nilcell;
>   ...
>   list l = empty;
> 
> Using the reference rules, we rewrite this as:
> 
> 	public typedef *elem list;
> 
> 	public list empty = &nilcell;
> 
>   list l = *empty;
> 
> As you can see, there is now a type mismatch -- reference types make 
> naming the referenced value easy and naming the referring value hard.  You 
> can "fix" this by using & here:
> 
>   list l = &empty;
> 
> That's because initializers for reference variables are a bit mystic -- 
> they compute the referring value rather than the referenced value.
> 
> To make this datatype work like you expect, you can either use pointers or 
> you can move the union:
> 
>   namespace List {
> 
>       public typedef list;
> 
>       typedef elem;
> 
>       public typedef union {
>           &elem cell;
>           void nil;
>       } list;
> 
>       typedef struct {
>          poly first;
>          list rest;
>       } elem;
> 
>       public list cons(poly v, list l) {
>           return (list) { cell = reference ((elem) { first = v, rest = l })};
>       }
> 
>       public poly car(list l) {
>           return l.cell.first;
>       }
> 
>       public list cdr(list l) {
>           return l.cell.rest;
>       }
> 
>       public bool null(list l) {
>           union switch(l) {
>               case cell c:
>                   return false;
>               case nil:
>                   return true;
>           }
>       }
> 
>       public list empty = { nil = <> };
>   }
> 
> -keith
> 
> 
> 
> _______________________________________________
> Nickle mailing list
> Nickle at nickle.org
> http://nickle.org/mailman/listinfo/nickle



More information about the Nickle mailing list