[nem-en] void as type parameter

Michal Moskal michal.moskal at gmail.com
Tue Jul 10 09:57:33 CEST 2007


On 7/3/07, Sandro Magi <smagi at higherlogics.com> wrote:
> That approach seems less-desirable for three reasons:
>
> 1. It's less type-safe: an unintended object reference might escape
> since everything can be implicitly cast to "object". This reduces the
> type safety when composing functions and values, as in parser
> combinators (I have a C# parser combinator library based on FP# for
> instance). A "Unit" struct can only be cast to object, so if we never
> use object as a parameter, we know that the code will not have runtime
> type errors and will not require runtime type checks (as long as we
> avoid other techniques that require type checks, like reflection).

I don't quite get it: you need an explicit cast to cast from the
object type anyhow.

>
> 2. Efficiency: I wonder if "new object()" returns a singleton, or
> allocates a new heap object every time. I would guess the latter.

Yes.

> Might
> as well just use a stack allocated value, but I'll have to run some
> simple benchmarks soon to see what the impact actually is.
>
> 3. Nullable values are just less safe overall. I'm wary of using null
> anywhere for obvious reasons I think.

I guess in this case the compiler would be able to ''prove'' that the
returned null would not be used anywhere.

Anyhow, I don't mind using something else, maybe except that you're
forcing program to link to Nemerle.dll once they use this feature.

>
> I haven't focused much on efficiency in the FP# library; the focus has
> been more on safety.
>
> Sandro
>
> Michal Moskal wrote:
> > One can as well use Object and pass null. I guess the overhead would
> > be similar. This is actually what we have done some time ago, but I
> > guess there were some cases where it didn't work, so Dimitry comitted
> > a patch to just disallow it. Investigating this further is on my TODO
> > list, but it somehow cannot get to the top...
> >
> > On 7/1/07, Sandro Magi <smagi at higherlogics.com> wrote:
> >> Yes, which is why I just created the empty "Unit" struct as a
> >> pseudo-void type to fake it. :-)
> >>
> >> Sandro
> >>
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>


-- 
   Michał


More information about the devel-en mailing list