Forums

Syntax for new constraint?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Syntax for new constraint?

Postby nevdelap » Thu Jul 22, 2010 9:17 pm

Hi. Quick one. What's the syntax for declaring a new constraint?

Code: Select all
def method<of T>
    where T must be XXX
    t = T() # error: Cannot create an instance of the variable
            # type "T" because it doesn"t have the new() constraint
    ...
call me Nev.
nevdelap
 
Posts: 61
Location: Buenos Aires

Re: Syntax for new constraint?

Postby hopscc » Fri Jul 23, 2010 5:06 am

rumour has it that you use callable

Code: Select all
class G1<of TArg>
        where TArg must be class, callable

        cue init
                base.init
                a = TArg()  # instantiate a generic parameter
                b = TArg()
                assert a is not b
                assert a.getHashCode
                assert b.getHashCode

see Tests/240-generics/300-declare-generic-classes/602-instantiate-generic-arg.cobra
and new constraint search

This stuff should be in the (NYI) wiki pages on generics
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 51 guests