Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread Zhao Xin via swift-users
Sorry Dave, I didn't notice that you said in `extension`. I just put the "where
Source == Displacement" to the original poster's code and the error showed.
My bad.

Zhao Xin

On Sun, Jul 9, 2017 at 1:56 PM, David Sweeris  wrote:

> Hmm... I just tried it in a playground, and it works:
> struct DistortedNoise {
>   let source:Source,
>   displacement:Displacement
>
>
>   init(source:Source, displacement:Displacement)
>   {
> self.source   = source
> self.displacement = displacement
>   }
>
>
> }
> extension DistortedNoise where Source == Displacement {
>   init(source:Source)
>   {
> self.source   = source
> self.displacement = source
>   }
> }
> let foo = DistortedNoise(source: 1) // DistortedNoise
> foo.source // 1
> foo.displacement // 1
>
> That's with Xcode 9b2, using the default Xcode 9.0 toolchain. With Xcode
> 8.3.3 and its default toolchain, the `let foo = ...` line outputs "
> __lldb_expr_2.DistortedNoise" instead of just "DistortedNoise Int>", but that's just a more... I think the word is "qualified"... name
> for the same thing.
>
> - Dave Sweeris
>
>
> On Jul 8, 2017, at 9:39 PM, Zhao Xin  wrote:
>
> No, David, it is now allowed.  "error: same-type requirement makes generic
> parameters 'Source' and 'Displacement' equivalent".
>
> Zhao Xin
>
> On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris via swift-users <
> swift-users@swift.org> wrote:
>
>> You could try putting that init in an extension "where Source ==
>> Displacement"
>>
>> > On Jul 8, 2017, at 21:06, Taylor Swift via swift-users <
>> swift-users@swift.org> wrote:
>> >
>> > I have a type like
>> >
>> > struct DistortedNoise where Source:Noise,
>> Displacement:Noise
>> > {
>> > let source:Source,
>> > displacement:Displacement
>> >
>> > init(source:Source, displacement:Displacement)
>> > {
>> > self.source   = source
>> > self.displacement = displacement
>> > }
>> >
>> > init(source:Source)
>> > {
>> > self.source   = source
>> > self.displacement = source
>> > }
>> > }
>> >
>> > and I get the error
>> >
>> > Compile Swift Module 'Noise' (5 sources)
>> > /home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source'
>> is not convertible to 'Displacement'
>> > self.displacement = source
>> > ^~
>> >
>> > How do I tell Swift that I want the same type fulfilling both Source
>> and Displacement?
>> >
>> > ___
>> > swift-users mailing list
>> > swift-users@swift.org
>> > https://lists.swift.org/mailman/listinfo/swift-users
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread David Sweeris via swift-users
Hmm... I just tried it in a playground, and it works:
struct DistortedNoise {
  let source:Source,
  displacement:Displacement
  
  init(source:Source, displacement:Displacement)
  {
self.source   = source
self.displacement = displacement
  }
  
}
extension DistortedNoise where Source == Displacement {
  init(source:Source)
  {
self.source   = source
self.displacement = source
  }
}
let foo = DistortedNoise(source: 1) // DistortedNoise
foo.source // 1
foo.displacement // 1

That's with Xcode 9b2, using the default Xcode 9.0 toolchain. With Xcode 8.3.3 
and its default toolchain, the `let foo = ...` line outputs 
"__lldb_expr_2.DistortedNoise" instead of just "DistortedNoise", but that's just a more... I think the word is "qualified"... name for 
the same thing.

- Dave Sweeris


> On Jul 8, 2017, at 9:39 PM, Zhao Xin  wrote:
> 
> No, David, it is now allowed.  "error: same-type requirement makes generic 
> parameters 'Source' and 'Displacement' equivalent".
> 
> Zhao Xin
> 
> On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris via swift-users 
> mailto:swift-users@swift.org>> wrote:
> You could try putting that init in an extension "where Source == Displacement"
> 
> > On Jul 8, 2017, at 21:06, Taylor Swift via swift-users 
> > mailto:swift-users@swift.org>> wrote:
> >
> > I have a type like
> >
> > struct DistortedNoise where Source:Noise, 
> > Displacement:Noise
> > {
> > let source:Source,
> > displacement:Displacement
> >
> > init(source:Source, displacement:Displacement)
> > {
> > self.source   = source
> > self.displacement = displacement
> > }
> >
> > init(source:Source)
> > {
> > self.source   = source
> > self.displacement = source
> > }
> > }
> >
> > and I get the error
> >
> > Compile Swift Module 'Noise' (5 sources)
> > /home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source' is not 
> > convertible to 'Displacement'
> > self.displacement = source
> > ^~
> >
> > How do I tell Swift that I want the same type fulfilling both Source and 
> > Displacement?
> >
> > ___
> > swift-users mailing list
> > swift-users@swift.org 
> > https://lists.swift.org/mailman/listinfo/swift-users 
> > 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread David Sweeris via swift-users
Oh, I hate that error! If there was ever a time I've wanted to have a 
conversation with the compiler... "yes, mr compiler, I know the same type 
requirement makes them equivalent; that's why I wrote it! Please compile 
anyway."

Which version of the compiler/language are you using?

Sent from my iPhone

> On Jul 8, 2017, at 21:39, Zhao Xin  wrote:
> 
> No, David, it is now allowed.  "error: same-type requirement makes generic 
> parameters 'Source' and 'Displacement' equivalent".
> 
> Zhao Xin
> 
>> On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris via swift-users 
>>  wrote:
>> You could try putting that init in an extension "where Source == 
>> Displacement"
>> 
>> > On Jul 8, 2017, at 21:06, Taylor Swift via swift-users 
>> >  wrote:
>> >
>> > I have a type like
>> >
>> > struct DistortedNoise where Source:Noise, 
>> > Displacement:Noise
>> > {
>> > let source:Source,
>> > displacement:Displacement
>> >
>> > init(source:Source, displacement:Displacement)
>> > {
>> > self.source   = source
>> > self.displacement = displacement
>> > }
>> >
>> > init(source:Source)
>> > {
>> > self.source   = source
>> > self.displacement = source
>> > }
>> > }
>> >
>> > and I get the error
>> >
>> > Compile Swift Module 'Noise' (5 sources)
>> > /home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source' is 
>> > not convertible to 'Displacement'
>> > self.displacement = source
>> > ^~
>> >
>> > How do I tell Swift that I want the same type fulfilling both Source and 
>> > Displacement?
>> >
>> > ___
>> > swift-users mailing list
>> > swift-users@swift.org
>> > https://lists.swift.org/mailman/listinfo/swift-users
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread Zhao Xin via swift-users
typealias now = not.

Zhao Xin

On Sun, Jul 9, 2017 at 12:39 PM, Zhao Xin  wrote:

> No, David, it is now allowed.  "error: same-type requirement makes generic
> parameters 'Source' and 'Displacement' equivalent".
>
> Zhao Xin
>
> On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris via swift-users <
> swift-users@swift.org> wrote:
>
>> You could try putting that init in an extension "where Source ==
>> Displacement"
>>
>> > On Jul 8, 2017, at 21:06, Taylor Swift via swift-users <
>> swift-users@swift.org> wrote:
>> >
>> > I have a type like
>> >
>> > struct DistortedNoise where Source:Noise,
>> Displacement:Noise
>> > {
>> > let source:Source,
>> > displacement:Displacement
>> >
>> > init(source:Source, displacement:Displacement)
>> > {
>> > self.source   = source
>> > self.displacement = displacement
>> > }
>> >
>> > init(source:Source)
>> > {
>> > self.source   = source
>> > self.displacement = source
>> > }
>> > }
>> >
>> > and I get the error
>> >
>> > Compile Swift Module 'Noise' (5 sources)
>> > /home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source'
>> is not convertible to 'Displacement'
>> > self.displacement = source
>> > ^~
>> >
>> > How do I tell Swift that I want the same type fulfilling both Source
>> and Displacement?
>> >
>> > ___
>> > swift-users mailing list
>> > swift-users@swift.org
>> > https://lists.swift.org/mailman/listinfo/swift-users
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread Zhao Xin via swift-users
No, David, it is now allowed.  "error: same-type requirement makes generic
parameters 'Source' and 'Displacement' equivalent".

Zhao Xin

On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris via swift-users <
swift-users@swift.org> wrote:

> You could try putting that init in an extension "where Source ==
> Displacement"
>
> > On Jul 8, 2017, at 21:06, Taylor Swift via swift-users <
> swift-users@swift.org> wrote:
> >
> > I have a type like
> >
> > struct DistortedNoise where Source:Noise,
> Displacement:Noise
> > {
> > let source:Source,
> > displacement:Displacement
> >
> > init(source:Source, displacement:Displacement)
> > {
> > self.source   = source
> > self.displacement = displacement
> > }
> >
> > init(source:Source)
> > {
> > self.source   = source
> > self.displacement = source
> > }
> > }
> >
> > and I get the error
> >
> > Compile Swift Module 'Noise' (5 sources)
> > /home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source' is
> not convertible to 'Displacement'
> > self.displacement = source
> > ^~
> >
> > How do I tell Swift that I want the same type fulfilling both Source and
> Displacement?
> >
> > ___
> > swift-users mailing list
> > swift-users@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-users
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread David Sweeris via swift-users
You could try putting that init in an extension "where Source == Displacement"

> On Jul 8, 2017, at 21:06, Taylor Swift via swift-users 
>  wrote:
> 
> I have a type like 
> 
> struct DistortedNoise where Source:Noise, 
> Displacement:Noise
> {
> let source:Source,
> displacement:Displacement
> 
> init(source:Source, displacement:Displacement)
> {
> self.source   = source
> self.displacement = displacement
> }
> 
> init(source:Source)
> {
> self.source   = source
> self.displacement = source
> }
> }
> 
> and I get the error 
> 
> Compile Swift Module 'Noise' (5 sources)
> /home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source' is not 
> convertible to 'Displacement'
> self.displacement = source
> ^~
> 
> How do I tell Swift that I want the same type fulfilling both Source and 
> Displacement?
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread Zhao Xin via swift-users
Please try this:

struct DistortedNoise where Source:Noise {

typealias Displacement = Source



let source:Source

let displacement:Displacement



init(source:Source, displacement:Displacement)

{

self.source   = source

self.displacement = displacement

}



init(source:Source)

{

self.source   = source

self.displacement = source

}

}


Zhao Xin

On Sun, Jul 9, 2017 at 12:21 PM, somu subscribe via swift-users <
swift-users@swift.org> wrote:

> Hi Taylor,
>
> If both Source and Displacement are going to be Noise, you could use just
> one placeholder type.
>
> class Noise {}
>
> struct DistortedNoise where Item:Noise
> {
> let source:Item,
> displacement:Item
>
>
> init(source:Item, displacement:Item)
> {
> self.source   = source
> self.displacement = displacement
> }
>
>
> init(source:Item)
> {
> self.source   = source
> self.displacement = source
> }
> }
>
> Regards,
> Muthu
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Filling two type parameters with the same type

2017-07-08 Thread somu subscribe via swift-users
Hi Taylor,

If both Source and Displacement are going to be Noise, you could use just one 
placeholder type.

class Noise {}

struct DistortedNoise where Item:Noise
{
let source:Item,
displacement:Item

init(source:Item, displacement:Item)
{
self.source   = source
self.displacement = displacement
}

init(source:Item)
{
self.source   = source
self.displacement = source
}
}

Regards,
Muthu___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Filling two type parameters with the same type

2017-07-08 Thread Taylor Swift via swift-users
I have a type like

struct DistortedNoise where Source:Noise,
Displacement:Noise
{
let source:Source,
displacement:Displacement

init(source:Source, displacement:Displacement)
{
self.source   = source
self.displacement = displacement
}

init(source:Source)
{
self.source   = source
self.displacement = source
}
}

and I get the error

Compile Swift Module 'Noise' (5 sources)
/home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source' is not
convertible to 'Displacement'
self.displacement = source
^~

How do I tell Swift that I want the same type fulfilling both Source and
Displacement?
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users