At present, the type system behind pointers is a bit of a mess. And we have an outstanding problem: you can have a pointer of type
ptr[T] = &T which cannot be NULL. You can have a pointer of type cptr[T] = @T which can be NULL. See class Cptr in std/cptr.flx. You can also have an incrementable pointer type: carray[T] = +T It's confusing but no, this is not an array, its a "C" array, that is, an incrementable pointer. But you cannot have a possibly NULL incrementable pointer. Of course I could define a type for that .. possibly_NULL_incrementable_pointer[T] It's important to note that &T is compiler intrinsic. However cptr and carray are defined in the library. And now we need to note that there's ANOTHER abstracted pointer type: varray[T] This also is "just a C pointer". It cannot be NULL. It isn't incrementable but it does represent an array. Unlike the other types, this one has a constuctor that ensures the pointer is garbage collected and the underlying length (both max length and currenly used length) is known. And the type can be found at run time dynamically. Ok, so I want you to look at this program: ////////////////////////// var x = 100; // sample data var px = &x; // a pointer var cpx : cptr[int] = cptr[int] px; var cp0 = nullptr[int]; println$ "Cptr cpx = " + cpx.address.str; println$ "Cptr cp0 = " + cp0.address.str; var opx = Some px; var o0 = None[&int]; println$ "Opt opx = " + str (C_hack::cast[address] (opx)); println$ "Opt o0 = " + str (C_hack::cast[address] (o0)); ///////////////////// and the output: ///////////////// Cptr cpx = 0x100100540 Cptr cp0 = 0x0 Opt opx = 0x100100540 Opt o0 = 0x0 ////////////// This demonstrates that the representation of opt[&T] is the same as &T: its just a pointer, with None represented by NULL. This means we can throw out @T and just use opt[&T] instead, with some name changes. I.e. None[&int] really does name NULL. If instead we define @T = opt[T] then we get these types: &T -- pointer to T @&T -- possibly NULL pointer to T +T -- incrementable pointer (C style array) @+T -- possibly NULL incrementable pointer The change in notation may break a few things. The changing in the naming may break a few more. The important point is that without any performance loss: ** we get a possibly NULL incrementable pointer for free ** we have a new compact notion for "optional" Actually it's tempting to use ?T instead. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language