« Return to Thread: Syntax for generic parameter declaration

Re: Syntax for generic parameter declaration

by Arron Washington-2 :: Rate this Message:

Reply to Author | View in Thread

??

public static def foobar(par1 as T, par2 as Z, par3 as Y)
   generic T : of, where constraint (optional)
   generic Z : of, where constraint (optional)
   generic Y

Cheat -- think outside the box and _cheat_. Stealing is preferrable if there's already a non-ugly syntax.

On 6/1/07, Doug H <doug00@...> wrote:



On May 31, 8:03 pm, Wraith <wrai...@...> wrote:

> Heres a rather lengthy example i pulled out of a c# project, to show
> what the syntax will look like when it gets unwieldy rather than the
> nice neat examples we've got here at the moment.
>
> public static def CreateTransitions[of TState(IEquatable[of
> TState]),TValue(IComparable[of TValue])](
>     stateMap as IDictionary[of ISet[of TState],TState],
>     states as IDictionary[of ISet[of TState],IDictionary[of
> Predicate[of TValue],ISet[of TState]]],
>     stateComparer as IEqualityComparer[of TState]
>     ) as IDictionary[of TState,IList[of ITransition[of
> TState,TValue]]]:
>     dict = TransitionDictionary[of TState,IList[of Transition[of
> TState,TValue]]](stateComparer)

Here it is with vb-like inline syntax like daniel mentioned, plus in
python style (no static, public when unnecessary):

def CreateTransitions[of TState as IEquatable[of TState], TValue as
IComparable[of TValue]] (
                            stateMap as IDictionary[of ISet[of
TState], TState],
                            states as IDictionary[of ISet[of TState],
IDictionary[of Predicate[of TValue],ISet[of TState]]],
                            stateComparer as IEqualityComparer[of
TState]
                           ) as IDictionary[of TState,IList[of
ITransition[of TState,TValue]]]:
      dict = TransitionDictionary[of TState, IList[of Transition[of
TState, TValue]]](stateComparer)


My earlier proposal was to put generic parameters at the beginning of
the normal parameters list so
people don't forget the parentheses.  This version requires less
parentheses and brackets.  You can
tell which parameters are generic by the "of" at the beginning:

def CreateTransitions(of TState as IEquatable of TState,  of TValue as
IComparable of TValue,
                    stateMap as IDictionary[of ISet of TState,
TState],
                    states as IDictionary[of ISet of TState,
IDictionary[of Predicate of TValue, ISet of TState]],
                    stateComparer as IEqualityComparer of TState
                   ) as IDictionary[of TState, IList of ITransition[of
TState,TValue]]:
      dict = TransitionDictionary(of TState, of IList of Transition[of
TState, TValue], stateComparer)

Here is a no-bracket version, cleaner on the eyes and more explicit
about which parameters are generic
(the brackets in all the other versions don't require "of" for generic
parameters after the first one in a list):

def CreateTransitions(of TState as IEquatable of TState,
                    of TValue as IComparable of TValue,
                    stateMap as IDictionary(of ISet of TState, of
TState),
                    states as IDictionary(of ISet of TState, of
IDictionary(of Predicate of TValue, of ISet of TState)),
                    stateComparer as IEqualityComparer of TState
                   ) as IDictionary(of TState, of IList of
ITransition(of TState, of TValue)):
      dict = TransitionDictionary(of TState, of IList of Transition(of
TState, of TValue), stateComparer)


> Why the 'of'? is there some place where indexing, slicing or some
> other use or [] is available in type definitions? it's be cleaner
> without the keyword and [] is already containing the list.

properties use [] in the type definition

Either way, "X[of Y]" or "X(of Y)" should be substitutable with "X of
Y" I believe.




http://geekninja.blogspot.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

 « Return to Thread: Syntax for generic parameter declaration