What is the type of 42?

Christopher Diggins — 2006-10-25 19:13:14

I am rethinking the expression of the types of literals in the Cat language.

Previously I had separated the notion of primitive types and
functions. Now I am thinking that all literals should be also
functions which yield themselves, like they are in Joy.

I've posted more about the rationale at
http://www.artima.com/weblogs/viewpost.jsp?thread=182140

Does anyone see any problem with expressing primitives types as
functions which generate themselves?

Christopher Diggins

Greg Buchholz — 2006-10-25 20:39:34

--- Christopher Diggins <cdiggins@...> wrote:

> Now I am thinking that all literals should be also
> functions which yield themselves

Is that definition recursive?

"...all literals should be functions which yield functions, which yield
functions, which yield functions, which..."

I think that things like numbers in Joy are a union of types, sometimes a
primitive value, sometimes a function which pushes a primitive value on
to the stack, depending on context. I think I probably understand what
you mean, but what about the following program...

42 [42] cons

...now does that final list have two elements of the same type
(presumably functions that push a number on the stack), or does it have
elements of two different types, a number and a function which pushes a
number on the stack.
I think for a statically typed lanugage, you might want to think
about differentiating between the type of lists and quotations. So that
you'd could have either...

42 42 unitlist cons [1 +] map

...or...

42 stackify 42 stackify compose i

...but mixing wouldn't be allowed.

Greg Buchholz


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

John Cowan — 2006-10-25 20:53:22

Greg Buchholz scripsit:

> I think that things like numbers in Joy are a union of types, sometimes a
> primitive value, sometimes a function which pushes a primitive value on
> to the stack, depending on context.

Or to put it another way:

Every object in Joy is invokable.

So 42 can be added to 23 (but not to "x", because "x" does not understand
addition), but all three can be invoked. Invocation is distributed over
the members of a list, but in all other cases causes the stack to grow
by one element. (Note that "i" is not primitive invocation.)

--
And it was said that ever after, if any John Cowan
man looked in that Stone, unless he had a cowan@...
great strength of will to turn it to other http://ccil.org/~cowan
purpose, he saw only two aged hands withering
in flame. --"The Pyre of Denethor"

Christopher Diggins — 2006-10-25 21:52:37

> > Now I am thinking that all literals should be also
> > functions which yield themselves
>
> Is that definition recursive?

Yes.

> "...all literals should be functions which yield functions, which yield
> functions, which yield functions, which..."
>
> I think that things like numbers in Joy are a union of types, sometimes a
> primitive value, sometimes a function which pushes a primitive value on
> to the stack, depending on context.

But the question remains: how do you express that formally in a static
type system?

> I think I probably understand what
> you mean, but what about the following program...
>
> 42 [42] cons
>
> ...now does that final list have two elements of the same type
> (presumably functions that push a number on the stack), or does it have
> elements of two different types, a number and a function which pushes a
> number on the stack.

This was precisely the question I was flip-flopping between. Both
answers seem valid to me.

> I think for a statically typed lanugage, you might want to think
> about differentiating between the type of lists and quotations. So that
> you'd could have either...
>
> 42 42 unitlist cons [1 +] map
>
> ...or...
>
> 42 stackify 42 stackify compose i
>
> ...but mixing wouldn't be allowed.

That is definitely a valid approach and is in fact the one that I use
in the current implementation of Cat (which I hope to release this
weekend if all goes well). The challenge of that approach is that it
is more verbose. I find myself comparing Cat code to Joy code, and
being jealous of the more powerful expressiveness of Joy.

However i still find myself asking is there any substantial reason not
to have ints as being self referential types which can be used
whereever a function is required?

Perhaps one convincing argument is that by separating primitive values
from functions yielding primitve values is that the type system can
more easily catch programming mistakes.

I am still straddling the fence on this issue.

-Christopher