Fused types syntax
In looking at merging fused types, it's time to nail down the syntax. The current implementation is ctypedef cython.fused_type(list, dict, object) fused_t This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about cython.fused_type[list, dict, object]. One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas? - Robert P.S. Anyone remember buffers and C++ templated types are dissallowed as typedefs?
Not that my opinion carriers any weight, but I'm +1 on this. On Thu, Jun 2, 2011 at 11:39 AM, Robert Bradshaw < robertwb@math.washington.edu> wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
- Robert
P.S. Anyone remember buffers and C++ templated types are dissallowed as typedefs? _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
On 2 June 2011 18:39, Robert Bradshaw <robertwb@math.washington.edu> wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
I like it, so I'll give another +1. Changing wouldn't be too much work anyways.
- Robert
P.S. Anyone remember buffers and C++ templated types are dissallowed as typedefs?
Yes, there's even a test for it: tests/errors/buffertypedef_T117.pyx (http://trac.cython.org/cython_trac/ticket/117). But it looks more like an easy fix than a feature.
_______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
On Thu, Jun 2, 2011 at 1:07 PM, mark florisson <markflorisson88@gmail.com> wrote:
On 2 June 2011 18:39, Robert Bradshaw <robertwb@math.washington.edu> wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
I like it, so I'll give another +1. Changing wouldn't be too much work anyways.
- Robert
P.S. Anyone remember buffers and C++ templated types are dissallowed as typedefs?
Yes, there's even a test for it: tests/errors/buffertypedef_T117.pyx (http://trac.cython.org/cython_trac/ticket/117). But it looks more like an easy fix than a feature.
I could see how for buffers it would require at bit more work, but for C++ types that shouldn't be a problem. In particular, I'm looking at https://github.com/cython/cython/blob/master/Cython/Compiler/Parsing.py#L261... - Robert
On 06/02/2011 06:39 PM, Robert Bradshaw wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
I don't really like overloading [] even more, and I think () (or, perhaps, 'fused_type([list, dict, object])'). But I don't feel very strongly about it. If you only want this allowed in typedefs, then, being puristic, I think that really a "fused type" is really different from a ctypedef, and that it would warrant something like a new keyword. cdef fusedtype [list, dict, object] fused_t That's rather horrible, but you get the gist. The thing is, once you use a ctypeudef, you really should allow def f(fused_type(float, double) x, fused_type(float, double) y): ... but then, how many fused types do you have, one or two? So this makes it seem to me that using ctypedef is a rather horrible hack. But, like I said, I don't feel strongly about this.
P.S. Anyone remember buffers and C++ templated types are dissallowed as typedefs?
As for buffers I just think I never got around to it... Dag Sverre
If you only want this allowed in typedefs, then, being puristic, I think
On Jun 2, 2011 2:18 PM, "Dag Sverre Seljebotn" <d.s.seljebotn@astro.uio.no> wrote: that really a "fused type" is really different from a ctypedef, and that it would warrant something like a new keyword.
cdef fusedtype [list, dict, object] fused_t
+1 (to some variant of this, not necessarily this exactly) I find the argument that defining the same fused type twice results in two different, incompatible types to be very compelling. That's a fundamental difference from typedefs. - Nathaniel
On Thu, Jun 2, 2011 at 2:18 PM, Dag Sverre Seljebotn <d.s.seljebotn@astro.uio.no> wrote:
On 06/02/2011 06:39 PM, Robert Bradshaw wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
I don't really like overloading [] even more, and I think () (or, perhaps, 'fused_type([list, dict, object])').
But I don't feel very strongly about it.
If you only want this allowed in typedefs, then, being puristic, I think that really a "fused type" is really different from a ctypedef, and that it would warrant something like a new keyword.
cdef fusedtype [list, dict, object] fused_t
That's rather horrible, but you get the gist. The thing is, once you use a ctypeudef, you really should allow
def f(fused_type(float, double) x, fused_type(float, double) y): ...
but then, how many fused types do you have, one or two?
Two, and you can't refer to them. Such anonymous types could be handy for one-off functions, e.g. def f(fused_type[list, dict, object] x): ... but maybe that's not needed.
So this makes it seem to me that using ctypedef is a rather horrible hack.
Yeah, this is the crux of the issue. (To be clear, Mark's implementation is good, it's our syntax that's hacky). It's perhaps less ugly than introducing a new keyword. A crazy idea: cdef fused floating_t: float double long double (in analogy with how we declare types like structs and enums).
But, like I said, I don't feel strongly about this.
P.S. Anyone remember buffers and C++ templated types are dissallowed as typedefs?
As for buffers I just think I never got around to it...
And in that case you can't just punt the typedef to C :). - Robert
On 2 June 2011 23:31, Robert Bradshaw <robertwb@math.washington.edu> wrote:
On Thu, Jun 2, 2011 at 2:18 PM, Dag Sverre Seljebotn <d.s.seljebotn@astro.uio.no> wrote:
On 06/02/2011 06:39 PM, Robert Bradshaw wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
I don't really like overloading [] even more, and I think () (or, perhaps, 'fused_type([list, dict, object])').
But I don't feel very strongly about it.
If you only want this allowed in typedefs, then, being puristic, I think that really a "fused type" is really different from a ctypedef, and that it would warrant something like a new keyword.
cdef fusedtype [list, dict, object] fused_t
That's rather horrible, but you get the gist. The thing is, once you use a ctypeudef, you really should allow
def f(fused_type(float, double) x, fused_type(float, double) y): ...
but then, how many fused types do you have, one or two?
Two, and you can't refer to them. Such anonymous types could be handy for one-off functions, e.g.
def f(fused_type[list, dict, object] x): ...
but maybe that's not needed.
So this makes it seem to me that using ctypedef is a rather horrible hack.
Yeah, this is the crux of the issue. (To be clear, Mark's implementation is good, it's our syntax that's hacky). It's perhaps less ugly than introducing a new keyword. A crazy idea:
cdef fused floating_t: float double long double
(in analogy with how we declare types like structs and enums).
I like that syntax, the bad thing about ctypedef for me is that everything goes on one line, at which point you have to start breaking them if they get too long (which can happen quite easily with lenghty names like 'long double complex'), which looks awkward. So much for trying to reduce grammar changes, though :)
But, like I said, I don't feel strongly about this.
P.S. Anyone remember buffers and C++ templated types are dissallowed as typedefs?
As for buffers I just think I never got around to it...
And in that case you can't just punt the typedef to C :).
- Robert _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
On Thu, Jun 2, 2011 at 2:42 PM, mark florisson <markflorisson88@gmail.com> wrote:
On 2 June 2011 23:31, Robert Bradshaw <robertwb@math.washington.edu> wrote:
On Thu, Jun 2, 2011 at 2:18 PM, Dag Sverre Seljebotn <d.s.seljebotn@astro.uio.no> wrote:
On 06/02/2011 06:39 PM, Robert Bradshaw wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
I don't really like overloading [] even more, and I think () (or, perhaps, 'fused_type([list, dict, object])').
But I don't feel very strongly about it.
If you only want this allowed in typedefs, then, being puristic, I think that really a "fused type" is really different from a ctypedef, and that it would warrant something like a new keyword.
cdef fusedtype [list, dict, object] fused_t
That's rather horrible, but you get the gist. The thing is, once you use a ctypeudef, you really should allow
def f(fused_type(float, double) x, fused_type(float, double) y): ...
but then, how many fused types do you have, one or two?
Two, and you can't refer to them. Such anonymous types could be handy for one-off functions, e.g.
def f(fused_type[list, dict, object] x): ...
but maybe that's not needed.
So this makes it seem to me that using ctypedef is a rather horrible hack.
Yeah, this is the crux of the issue. (To be clear, Mark's implementation is good, it's our syntax that's hacky). It's perhaps less ugly than introducing a new keyword. A crazy idea:
cdef fused floating_t: float double long double
(in analogy with how we declare types like structs and enums).
I like that syntax, the bad thing about ctypedef for me is that everything goes on one line, at which point you have to start breaking them if they get too long (which can happen quite easily with lenghty names like 'long double complex'), which looks awkward.
So much for trying to reduce grammar changes, though :)
Well, it introduces a new kind of node, rather than the kind of funny interaction/restriction with typedef, which got me thinking about this in the first place. Of course then you can't create an anonymous one for use in a function (which may be viewed as a feature or a defect). - Robert
On 06/02/2011 11:51 PM, Robert Bradshaw wrote:
On Thu, Jun 2, 2011 at 2:42 PM, mark florisson <markflorisson88@gmail.com> wrote:
On 2 June 2011 23:31, Robert Bradshaw<robertwb@math.washington.edu> wrote:
On Thu, Jun 2, 2011 at 2:18 PM, Dag Sverre Seljebotn <d.s.seljebotn@astro.uio.no> wrote:
On 06/02/2011 06:39 PM, Robert Bradshaw wrote:
In looking at merging fused types, it's time to nail down the syntax. The current implementation is
ctypedef cython.fused_type(list, dict, object) fused_t
This requires an addition to the grammer to allow the "call" syntax in a type declaration, as well as special casing to make it allowed only in a typedef. What about
cython.fused_type[list, dict, object].
One advantage is that indexing is already valid in type declarations, and its the typical syntax for parameterized types. Thoughts? Any other ideas?
I don't really like overloading [] even more, and I think () (or, perhaps, 'fused_type([list, dict, object])').
But I don't feel very strongly about it.
If you only want this allowed in typedefs, then, being puristic, I think that really a "fused type" is really different from a ctypedef, and that it would warrant something like a new keyword.
cdef fusedtype [list, dict, object] fused_t
That's rather horrible, but you get the gist. The thing is, once you use a ctypeudef, you really should allow
def f(fused_type(float, double) x, fused_type(float, double) y): ...
but then, how many fused types do you have, one or two?
Two, and you can't refer to them. Such anonymous types could be handy for one-off functions, e.g.
def f(fused_type[list, dict, object] x): ...
but maybe that's not needed.
So this makes it seem to me that using ctypedef is a rather horrible hack.
Yeah, this is the crux of the issue. (To be clear, Mark's implementation is good, it's our syntax that's hacky). It's perhaps less ugly than introducing a new keyword. A crazy idea:
cdef fused floating_t: float double long double
(in analogy with how we declare types like structs and enums).
I like that syntax, the bad thing about ctypedef for me is that everything goes on one line, at which point you have to start breaking them if they get too long (which can happen quite easily with lenghty names like 'long double complex'), which looks awkward.
So much for trying to reduce grammar changes, though :)
Well, it introduces a new kind of node, rather than the kind of funny interaction/restriction with typedef, which got me thinking about this in the first place. Of course then you can't create an anonymous one for use in a function (which may be viewed as a feature or a defect).
I'm +1 on this syntax, I really like it in fact. It also leaves a lot more room for anything else one might need to add in eventually (the "paired" idea of Pauli and so on). And I think not being able to create an anonymous one is a feature. Dag Sverre
participants (5)
-
Chris Colbert -
Dag Sverre Seljebotn -
mark florisson -
Nathaniel Smith -
Robert Bradshaw