The use of fixed type parameters

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

The use of fixed type parameters

Pimm Hogeling
Good day,

I'm doing some experiments with haXe, and ran into something I'd like to discuss with you all.

I have this code:
class Main {
    public static function main():Void {
        var specification:ISpecification<String> = new NotLongerThanSpecification(6);
        trace(specification.determineSatisfaction("Short"));
        trace(specification.determineSatisfaction("Way too long!"));
    }
}
interface ISpecification<T> {
    public function determineSatisfaction(value:T):Bool;
}
class NotLongerThanSpecification<String> implements ISpecification<String> {
    private var maxLength:UInt;
    public function new(maxLength:UInt):Void {
        this.maxLength = maxLength;
    }
    public function determineSatisfaction(value:String):Bool {
        return value.length <= maxLength;
    }
}

An ISpecification interface is defined, and it has a type parameter T since it should be usable for all types. The NotLongerThanSpecification implementation, however, is specifically for Strings. Now, since value is a String, I want to use it's length property. I get the following error:
NotLongerThanSpecification.String has no field length

Inserting untyped before value makes it all work.

Am I missing something here? Should I apply "fixed" type parameters in some other way?

Thanks in advance.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: The use of fixed type parameters

Heinz Hölzer-2
class NotLongerThanSpecification<String> implements ISpecification<String> {

should be

class NotLongerThanSpecification implements ISpecification<String> {

Pimm Hogeling schrieb:

> Good day,
>
> I'm doing some experiments with haXe, and ran into something I'd like
> to discuss with you all.
>
> I have this code:
> class Main {
>     public static function main():Void {
>         var specification:ISpecification<String> = new
> NotLongerThanSpecification(6);
>         trace(specification.determineSatisfaction("Short"));
>         trace(specification.determineSatisfaction("Way too long!"));
>     }
> }
> interface ISpecification<T> {
>     public function determineSatisfaction(value:T):Bool;
> }
> class NotLongerThanSpecification<String> implements
> ISpecification<String> {
>     private var maxLength:UInt;
>     public function new(maxLength:UInt):Void {
>         this.maxLength = maxLength;
>     }
>     public function determineSatisfaction(value:String):Bool {
>         return value.length <= maxLength;
>     }
> }
>
> An ISpecification interface is defined, and it has a type parameter T
> since it should be usable for all types. The
> NotLongerThanSpecification implementation, however, is specifically
> for Strings. Now, since value is a String, I want to use it's length
> property. I get the following error:
> NotLongerThanSpecification.String has no field length
>
> Inserting untyped before value makes it all work.
>
> Am I missing something here? Should I apply "fixed" type parameters in
> some other way?
>
> Thanks in advance.


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: The use of fixed type parameters

Pimm Hogeling
Hello Heinz,

Changing the NotLongerThanSpecification class to the following:
class NotLongerThanSpecification implements ISpecification<String> {
    private var maxLength:UInt;
    public function new(maxLength:UInt):Void {
        this.maxLength = maxLength;
    }
    public function determineSatisfaction(value:String):Bool {
        return (cast value.length) <= maxLength;
    }
}

Throws this (runtime) error:
VerifyError: Error #1053: Illegal override of NotLongerThanSpecification in nl.sandmen.team.NotLongerThanSpecification.

Any ideas?

Thanks.

2009/8/25 Heinz Hölzer <[hidden email]>
class NotLongerThanSpecification<String> implements ISpecification<String> {

should be

class NotLongerThanSpecification implements ISpecification<String> {

Pimm Hogeling schrieb:

Good day,

I'm doing some experiments with haXe, and ran into something I'd like to discuss with you all.

I have this code:
class Main {
   public static function main():Void {
       var specification:ISpecification<String> = new NotLongerThanSpecification(6);
       trace(specification.determineSatisfaction("Short"));
       trace(specification.determineSatisfaction("Way too long!"));
   }
}
interface ISpecification<T> {
   public function determineSatisfaction(value:T):Bool;
}
class NotLongerThanSpecification<String> implements ISpecification<String> {
   private var maxLength:UInt;
   public function new(maxLength:UInt):Void {
       this.maxLength = maxLength;
   }
   public function determineSatisfaction(value:String):Bool {
       return value.length <= maxLength;
   }
}

An ISpecification interface is defined, and it has a type parameter T since it should be usable for all types. The NotLongerThanSpecification implementation, however, is specifically for Strings. Now, since value is a String, I want to use it's length property. I get the following error:
NotLongerThanSpecification.String has no field length

Inserting untyped before value makes it all work.

Am I missing something here? Should I apply "fixed" type parameters in some other way?

Thanks in advance.


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: The use of fixed type parameters

Mark de Bruijn | Dykam
Scaling the problem down, even when typing specification with NotLongerThanSpecification, it doesn't run.

On Tue, Aug 25, 2009 at 12:05 PM, Pimm Hogeling <[hidden email]> wrote:
Hello Heinz,

Changing the NotLongerThanSpecification class to the following:

class NotLongerThanSpecification implements ISpecification<String> {
    private var maxLength:UInt;
    public function new(maxLength:UInt):Void {
        this.maxLength = maxLength;
    }
    public function determineSatisfaction(value:String):Bool {
        return (cast value.length) <= maxLength;
    }
}

Throws this (runtime) error:
VerifyError: Error #1053: Illegal override of NotLongerThanSpecification in nl.sandmen.team.NotLongerThanSpecification.

Any ideas?

Thanks.

2009/8/25 Heinz Hölzer <[hidden email]>

class NotLongerThanSpecification<String> implements ISpecification<String> {

should be

class NotLongerThanSpecification implements ISpecification<String> {

Pimm Hogeling schrieb:

Good day,

I'm doing some experiments with haXe, and ran into something I'd like to discuss with you all.

I have this code:
class Main {
   public static function main():Void {
       var specification:ISpecification<String> = new NotLongerThanSpecification(6);
       trace(specification.determineSatisfaction("Short"));
       trace(specification.determineSatisfaction("Way too long!"));
   }
}
interface ISpecification<T> {
   public function determineSatisfaction(value:T):Bool;
}
class NotLongerThanSpecification<String> implements ISpecification<String> {
   private var maxLength:UInt;
   public function new(maxLength:UInt):Void {
       this.maxLength = maxLength;
   }
   public function determineSatisfaction(value:String):Bool {
       return value.length <= maxLength;
   }
}

An ISpecification interface is defined, and it has a type parameter T since it should be usable for all types. The NotLongerThanSpecification implementation, however, is specifically for Strings. Now, since value is a String, I want to use it's length property. I get the following error:
NotLongerThanSpecification.String has no field length

Inserting untyped before value makes it all work.

Am I missing something here? Should I apply "fixed" type parameters in some other way?

Thanks in advance.


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: The use of fixed type parameters

Heinz Hölzer-2
In reply to this post by Pimm Hogeling
strange, it works in neko, but not in flash.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: The use of fixed type parameters

Mark de Bruijn | Dykam
Hmm, a target bug. It's also funny that the initial example compiled, as why does the interface accept the public keyword?

Sidenote, runs fine with C# too.

2009/8/25 Heinz Hölzer <[hidden email]>
strange, it works in neko, but not in flash.

--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: The use of fixed type parameters

Pimm Hogeling
I put public before all the methods in interfaces, haXe seems to take it.

On Tue, Aug 25, 2009 at 12:47, Mark de Bruijn <[hidden email]> wrote:
Hmm, a target bug. It's also funny that the initial example compiled, as why does the interface accept the public keyword?

Sidenote, runs fine with C# too.

2009/8/25 Heinz Hölzer <[hidden email]>
strange, it works in neko, but not in flash.

--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: The use of fixed type parameters

Franco Ponticelli
In reply to this post by Mark de Bruijn | Dykam

It's also funny that the initial example compiled, as why does the interface accept the public keyword?

Public is the default access modifier for interfaces but can be stated explicitly because private can be used too ... even if I have not yet found a reason for it ;)

Franco

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: The use of fixed type parameters

Nicolas Cannasse
In reply to this post by Pimm Hogeling
Pimm Hogeling a écrit :
> Good day,
>
> I'm doing some experiments with haXe, and ran into something I'd like to
> discuss with you all.
[...]
> interface ISpecification<T> {
>     public function determineSatisfaction(value:T):Bool;
> }
> class NotLongerThanSpecification<String> implements ISpecification<String> {

This is a known issue with Flash9+

It occurs when you are implementing or overriding a generic method with
a specific type.

The compiler will generate a fully typed method which is correct for
haXe but is refused by the Flash bytecode checker, which requires the
implemented/overriden method type to be exactly the same (this is
similar to using UInt instead of Int).

This will be fixed in future haXe releases.

Nicolas


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: The use of fixed type parameters

Mark de Bruijn | Dykam
Don't know if it's FlashDevelops or haXe's error, but when setting the target to flash 10, whcih I see appear in the build command, the error occurs too. Which flash targets aren't involved?

On Tue, Aug 25, 2009 at 12:57 PM, Nicolas Cannasse <[hidden email]> wrote:
Pimm Hogeling a écrit :

Good day,

I'm doing some experiments with haXe, and ran into something I'd like to discuss with you all.
[...]

interface ISpecification<T> {
   public function determineSatisfaction(value:T):Bool;
}
class NotLongerThanSpecification<String> implements ISpecification<String> {

This is a known issue with Flash9+

It occurs when you are implementing or overriding a generic method with a specific type.

The compiler will generate a fully typed method which is correct for haXe but is refused by the Flash bytecode checker, which requires the implemented/overriden method type to be exactly the same (this is similar to using UInt instead of Int).

This will be fixed in future haXe releases.

Nicolas


--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: The use of fixed type parameters

Pimm Hogeling
As Nicolas stated, only the Flash 9+ target is affected.

Thanks for the replies, everyone.

On Tue, Aug 25, 2009 at 13:02, Mark de Bruijn <[hidden email]> wrote:
Don't know if it's FlashDevelops or haXe's error, but when setting the target to flash 10, whcih I see appear in the build command, the error occurs too. Which flash targets aren't involved?


On Tue, Aug 25, 2009 at 12:57 PM, Nicolas Cannasse <[hidden email]> wrote:
Pimm Hogeling a écrit :

Good day,

I'm doing some experiments with haXe, and ran into something I'd like to discuss with you all.
[...]

interface ISpecification<T> {
   public function determineSatisfaction(value:T):Bool;
}
class NotLongerThanSpecification<String> implements ISpecification<String> {

This is a known issue with Flash9+

It occurs when you are implementing or overriding a generic method with a specific type.

The compiler will generate a fully typed method which is correct for haXe but is refused by the Flash bytecode checker, which requires the implemented/overriden method type to be exactly the same (this is similar to using UInt instead of Int).

This will be fixed in future haXe releases.

Nicolas


--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org