Syntax for generic parameter declaration

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

Syntax for generic parameter declaration

by Avishay Lavie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello.

Is there a proposed syntax for generic parameter declarations?  It's
easy enough to declare generic parameters without constraints:

  public class MyGenericClass of T:
    pass

  public class MyGenericClass[of T1, T2]:
    pass

But I have no idea what the syntax should be for constraints.
In C#, generic parameter constraints are introduced after their type
declaration, by using the where keyword:

  public class MyGenericClass<T1, T2>
    where T1 : struct
    where T2 : IComparable, new()

How would this be written in Boo?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Daniel Grunwald :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


This is the syntax VB uses:
Public Class MyGenericClass(Of T1 As Structure, T2 As {IComparable, New})

As Boo is also using "of" and "as", we could use something similar.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Avishay Lavie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I thought about having the constraints right after the parameters, but
I really don't like the braces to indicate multiple constraints.

How about:

  public class MyGenericClass[of T1, T2]
    when T1 is struct
    when T2 is IComparable, callable

This uses existing reserved words, although I'm not sure about using
"callable" to indicate a default constructor constraint.

On May 22, 4:15 pm, Daniel Grunwald <dan...@...> wrote:
> This is the syntax VB uses:
> Public Class MyGenericClass(Of T1 As Structure, T2 As {IComparable, New})
>
> As Boo is also using "of" and "as", we could use something similar.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Ayende Rahien-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why not:

public class MyGenericClass[of T1, T2]
   when T1 is struct
   when T2 is IComparable, constructor




On 5/23/07, Avish <some.avish@...> wrote:

I thought about having the constraints right after the parameters, but
I really don't like the braces to indicate multiple constraints.

How about:

  public class MyGenericClass[of T1, T2]
    when T1 is struct
    when T2 is IComparable, callable

This uses existing reserved words, although I'm not sure about using
"callable" to indicate a default constructor constraint.

On May 22, 4:15 pm, Daniel Grunwald < dan...@...> wrote:
> This is the syntax VB uses:
> Public Class MyGenericClass(Of T1 As Structure, T2 As {IComparable, New})
>
> As Boo is also using "of" and "as", we could use something similar.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Cedric Vivier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 5/23/07, Avish <some.avish@...> wrote:
> How about:
> public class MyGenericClass[of T1, T2]
>     when T1 is struct
>     when T2 is IComparable, callable
>
> This uses existing reserved words, although I'm not sure about using
> "callable" to indicate a default constructor constraint.

I'm not fond of it either.
How about:

when T2 is IComparable()

Maybe not very "legal-looking" but it may be more obvious because of
the similar look with the syntax for instantiating types.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Ayende Rahien-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How would you handle it when you don't want interface constraint?

On 5/23/07, Cedric Vivier <cedricv@...> wrote:

On 5/23/07, Avish <some.avish@...> wrote:
> How about:
> public class MyGenericClass[of T1, T2]
>     when T1 is struct
>     when T2 is IComparable, callable
>
> This uses existing reserved words, although I'm not sure about using
> "callable" to indicate a default constructor constraint.

I'm not fond of it either.
How about:

when T2 is IComparable()

Maybe not very "legal-looking" but it may be more obvious because of
the similar look with the syntax for instantiating types.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Wraith-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Is there a specific reason to follow the c# and VB idioms of declaring
constraints after all the types? IL does this inline for each argument
which could be cleaner and may well be easier to describe in a
grammar. Something like:

public class MyGenericClass[of T1 is struct, T2 is (IComparable,
constructor)]

I can't say i like the brackets much but it needs some way to separate
the generic argument listing mode from the constraint listing mode or
you end up guessing what sort of thing the current identifier is.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Wraith-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Is there a specific reason to follow the c# and VB idioms of declaring
constraints after all the types? IL does this inline for each argument
which could be cleaner and may well be easier to describe in a
grammar. Something like:

public class MyGenericClass[of T1 is struct, T2 is (IComparable[of
T2], constructor)]

I can't say i like the brackets much but it needs some way to separate
the generic argument listing mode from the constraint listing mode or
you end up guessing what sort of thing the current identifier is. YOu
could leave out the commas and use spaces to separate entries but it
seems somehow unbooish to have a naked whitespace separated list.

Is there any plan to allow explicit covariant and contravariant
constraints on delegates and interfaces? I think the IL +/- syntax
works adequately for this as well though you could just add the two as
keywords for the constraints list.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by George-94 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The variant
public class MyGenericClass[of T1 is struct, T2 is (IComparable[of
T2], constructor)] is the best. But 'is' has little different meaning
in Boo, so may be

public class MyGenericClass[of T1 (struct), T2  (IComparable[of
T2], constructor)]  ?

On 23 май, 15:35, Wraith <wrai...@...> wrote:

> Is there a specific reason to follow the c# and VB idioms of declaring
> constraints after all the types? IL does this inline for each argument
> which could be cleaner and may well be easier to describe in a
> grammar. Something like:
>
> public class MyGenericClass[of T1 is struct, T2 is (IComparable[of
> T2], constructor)]
>
> I can't say i like the brackets much but it needs some way to separate
> the generic argument listing mode from the constraint listing mode or
> you end up guessing what sort of thing the current identifier is. YOu
> could leave out the commas and use spaces to separate entries but it
> seems somehow unbooish to have a naked whitespace separated list.
>
> Is there any plan to allow explicit covariant and contravariant
> constraints on delegates and interfaces? I think the IL +/- syntax
> works adequately for this as well though you could just add the two as
> keywords for the constraints list.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by George-94 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The variant
public class MyGenericClass[of T1 is struct, T2 is (IComparable[of
T2], constructor)] is the best. But 'is' has little different meaning
in Boo, so may be

public class MyGenericClass[of T1 (struct), T2  (IComparable[of
T2], constructor)]  ?

On 23 май, 15:35, Wraith <wrai...@...> wrote:

> Is there a specific reason to follow the c# and VB idioms of declaring
> constraints after all the types? IL does this inline for each argument
> which could be cleaner and may well be easier to describe in a
> grammar. Something like:
>
> public class MyGenericClass[of T1 is struct, T2 is (IComparable[of
> T2], constructor)]
>
> I can't say i like the brackets much but it needs some way to separate
> the generic argument listing mode from the constraint listing mode or
> you end up guessing what sort of thing the current identifier is. YOu
> could leave out the commas and use spaces to separate entries but it
> seems somehow unbooish to have a naked whitespace separated list.
>
> Is there any plan to allow explicit covariant and contravariant
> constraints on delegates and interfaces? I think the IL +/- syntax
> works adequately for this as well though you could just add the two as
> keywords for the constraints list.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Rodrigo B. de Oliveira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I had these notes hanging around here:

class Whatever of T:
    given T(), T isa IEnumerable # combining in the same line
    given T() # single constraint per line is also possible
    given T isa struct

I like the way they read. And given was a planned keyword.

How do you like it?

On 5/22/07, Avish <some.avish@...> wrote:

>
> Hello.
>
> Is there a proposed syntax for generic parameter declarations?  It's
> easy enough to declare generic parameters without constraints:
>
>   public class MyGenericClass of T:
>     pass
>
>   public class MyGenericClass[of T1, T2]:
>     pass
>
> But I have no idea what the syntax should be for constraints.
> In C#, generic parameter constraints are introduced after their type
> declaration, by using the where keyword:
>
>   public class MyGenericClass<T1, T2>
>     where T1 : struct
>     where T2 : IComparable, new()
>
> How would this be written in Boo?
>
>
> >
>


--
bamboo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Avishay Lavie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hey, I really like this. However I think the constraints should occur
before the colon:

class Whatever[of T1, T2] given T1 isa struct, given T2(), T2 isa
IEnumerable:
  pass

or with linebreaks:

class Whatever[of T1, T2]
given T1 isa struct,
given T2(), T2 isa IEnumerable:
  pass

That way there's a clearer separation between declaration and body.
What do you say?

On May 23, 5:41 pm, "Rodrigo B. de Oliveira" <rodrigobam...@...>
wrote:

> I had these notes hanging around here:
>
> class Whatever of T:
>     given T(), T isa IEnumerable # combining in the same line
>     given T() # single constraint per line is also possible
>     given T isa struct
>
> I like the way they read. And given was a planned keyword.
>
> How do you like it?
>
> On 5/22/07, Avish <some.av...@...> wrote:
>
>
>
>
>
> > Hello.
>
> > Is there a proposed syntax for generic parameter declarations?  It's
> > easy enough to declare generic parameters without constraints:
>
> >   public class MyGenericClass of T:
> >     pass
>
> >   public class MyGenericClass[of T1, T2]:
> >     pass
>
> > But I have no idea what the syntax should be for constraints.
> > In C#, generic parameter constraints are introduced after their type
> > declaration, by using the where keyword:
>
> >   public class MyGenericClass<T1, T2>
> >     where T1 : struct
> >     where T2 : IComparable, new()
>
> > How would this be written in Boo?
>
> --
> bamboo


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Wraith-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On May 23, 7:33 pm, Avish <some.av...@...> wrote:

> That way there's a clearer separation between declaration and body.
> What do you say?

If the constraints really have to follow the closing of the generic
parameter block then they need to go before the terminal colon of the
definition or they're just going to be too confusing. They're a part
of the definition not of the body. Before colon is much better than
after if that's the only syntax in consideration.

I'm not sure i like the forced multiline idea because it adds an extra
line for each parameter i have to constrain and generics tend to be
quite viral when you use them a lot, it will force a lot of noisy
vertical space everywhere you want to consume something.

Is there a particular reason that you want to keep the declaration and
the constraints in separate places in the definition?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Avishay Lavie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I can't think of a way to declare constraints right there with the
parameters themselves without some ugly bracketing to support multiple
constraints. Do you have any suggestions?

On May 23, 10:26 pm, Wraith <wrai...@...> wrote:

> On May 23, 7:33 pm, Avish <some.av...@...> wrote:
>
> > That way there's a clearer separation between declaration and body.
> > What do you say?
>
> If the constraints really have to follow the closing of the generic
> parameter block then they need to go before the terminal colon of the
> definition or they're just going to be too confusing. They're a part
> of the definition not of the body. Before colon is much better than
> after if that's the only syntax in consideration.
>
> I'm not sure i like the forced multiline idea because it adds an extra
> line for each parameter i have to constrain and generics tend to be
> quite viral when you use them a lot, it will force a lot of noisy
> vertical space everywhere you want to consume something.
>
> Is there a particular reason that you want to keep the declaration and
> the constraints in separate places in the definition?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Wraith-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> I can't think of a way to declare constraints right there with the
> parameters themselves without some ugly bracketing to support multiple
> constraints. Do you have any suggestions?

Given that you have to be able to specify a list you need some way to
delimit it, i don't think you can avoid some kind or bracketing unless
you go to implicit delimiters like whitespace. The best i can think of
is to echo type inheritance syntax as George suggested earlier. Like
this:

public class MyGenericClass[of T1(struct), T2(IComparable[of T2],
constructor)]:


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Avishay Lavie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


That could actually work, and is a simpler grammar. Bamboo?

On May 24, 10:30 pm, Wraith <wrai...@...> wrote:

> > I can't think of a way to declare constraints right there with the
> > parameters themselves without some ugly bracketing to support multiple
> > constraints. Do you have any suggestions?
>
> Given that you have to be able to specify a list you need some way to
> delimit it, i don't think you can avoid some kind or bracketing unless
> you go to implicit delimiters like whitespace. The best i can think of
> is to echo type inheritance syntax as George suggested earlier. Like
> this:
>
> public class MyGenericClass[of T1(struct), T2(IComparable[of T2],
> constructor)]:


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Jb Evain-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Suggestion:

// only have new line if you want

class Foo[of T, Y, Z]
    given T isa struct and
    given Y() isa NiceThing and
    given Z isa class:

// new lines are ugly for methods

    def Bar[of X]() given X isa IEnumerable[of T]:
        pass

On 5/24/07, Avish <some.avish@...> wrote:

>
> That could actually work, and is a simpler grammar. Bamboo?
>
> On May 24, 10:30 pm, Wraith <wrai...@...> wrote:
> > > I can't think of a way to declare constraints right there with the
> > > parameters themselves without some ugly bracketing to support multiple
> > > constraints. Do you have any suggestions?
> >
> > Given that you have to be able to specify a list you need some way to
> > delimit it, i don't think you can avoid some kind or bracketing unless
> > you go to implicit delimiters like whitespace. The best i can think of
> > is to echo type inheritance syntax as George suggested earlier. Like
> > this:
> >
> > public class MyGenericClass[of T1(struct), T2(IComparable[of T2],
> > constructor)]:
>
>
> >
>


--
Jb

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Cedric Vivier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 5/27/07, Jb Evain <jb@...> wrote:
> class Foo[of T, Y, Z]
>     given T isa struct and
>     given Y() isa NiceThing and
>     given Z isa class:

My new favorite :)
The second line does not look as awkward as my previous suggestion of
introducing "()" in the pot.
Not sure about using "given" instead of "with" though.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by az-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> // only have new line if you want
>
> class Foo[of T, Y, Z]
>     given T isa struct and
>     given Y() isa NiceThing and
>     given Z isa class:

Looks pretty!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Syntax for generic parameter declaration

by Georges Benatti Jr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


+ 1

On 5/30/07, az <al.zatv@...> wrote:

>
> > // only have new line if you want
> >
> > class Foo[of T, Y, Z]
> >     given T isa struct and
> >     given Y() isa NiceThing and
> >     given Z isa class:
>
> Looks pretty!
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---

< Prev | 1 - 2 | Next >