jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • X10
  • XTENLANG-116

Can we write a generic Array.sum method?

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Won't Fix
  • Affects Version/s: X10 2.0.4
  • Fix Version/s: None
  • Component/s: Language Design
  • Labels:
    None

Description

public interface AO[T] {

    public operator + this: T;
    public operator - this: T;

    public operator this + (that: T): T;
    public operator this - (that: T): T;
    public operator this * (that: T): T;
    public operator this / (that: T): T;
    public operator this % (that: T): T;
}

class A[T] implements (Int)=>T {

    val t:T;

    public def apply(int):T = t;

    def sum() {T <: AO[T]} {
        var s:T = 0 as T; // generic additive identity
        s += this(0); // generic addition
        return s;
    }

    def this(t:T) {
        this.t = t;
    }
}

public class Bug {
    public static def main(args:Rail[String]) {
        val a = new A[Int](1);
        System.out.println("a.sum() " + a.sum());
    }
}

This attempt doesn't work because

  1. the primitive types don't declare that they implement +, etc. and

  2. there's no notion of a generic additive identity - seems like this might be a static field of the primitive types, but we can't access static fields of type parameters...

Or is there some other way to do this that I'm missing?

Issue Links

is depended upon by

Task - A task that needs to be done. XTENLANG-962 Array library redesign

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Bruce Lucas added a comment - 18/Oct/08 10:44 AM - edited

Affects

Array/TestSimpleArrayMult
Array/IntArrayMaxAbs

Show
Bruce Lucas added a comment - 18/Oct/08 10:44 AM - edited Affects Array/TestSimpleArrayMult Array/IntArrayMaxAbs
Hide
Permalink
Bruce Lucas added a comment - 20/Oct/08 7:36 AM

Same issue applies to Array.reduce w.r.t. the generic additive identity.

Show
Bruce Lucas added a comment - 20/Oct/08 7:36 AM Same issue applies to Array.reduce w.r.t. the generic additive identity.
Hide
Permalink
Igor Peshansky added a comment - 11/May/09 10:27 AM

Defer to 1.7.5

Show
Igor Peshansky added a comment - 11/May/09 10:27 AM Defer to 1.7.5
Hide
Permalink
David Grove added a comment - 23/Jun/09 12:41 PM

defer all open 1.7.5 issues to 1.9.1

Show
David Grove added a comment - 23/Jun/09 12:41 PM defer all open 1.7.5 issues to 1.9.1
Hide
Permalink
David Grove added a comment - 09/Dec/09 10:52 AM

Targeting major redesign of the Array library to 2.1.

Show
David Grove added a comment - 09/Dec/09 10:52 AM Targeting major redesign of the Array library to 2.1.
Hide
Permalink
Igor Peshansky added a comment - 15/Jun/10 9:47 PM

This is a language design issue. Item 1 above will be addressed by the work on operator lookup and coercions, but we still have no way of addressing item 2, namely the identity... Perhaps the default values design may help with that. Still, no way to fix this in the frontend until we have a spec.

Show
Igor Peshansky added a comment - 15/Jun/10 9:47 PM This is a language design issue. Item 1 above will be addressed by the work on operator lookup and coercions, but we still have no way of addressing item 2, namely the identity... Perhaps the default values design may help with that. Still, no way to fix this in the frontend until we have a spec.
Hide
Permalink
David Grove added a comment - 13/Jul/10 12:53 PM

Don't expect the needed generic mechanisms to become available any time soon. If they happen to arrive eventually, then we could look at doing this.

Show
David Grove added a comment - 13/Jul/10 12:53 PM Don't expect the needed generic mechanisms to become available any time soon. If they happen to arrive eventually, then we could look at doing this.

People

  • Assignee:
    Vijay Saraswat
    Reporter:
    Bruce Lucas
Vote (0)
Watch (0)

Dates

  • Created:
    16/Oct/08 10:30 AM
    Updated:
    13/Jul/10 12:53 PM
    Resolved:
    13/Jul/10 12:53 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.