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

Taylor Swift kelvin13ma at gmail.com
Sat Jul 8 22:57:30 CDT 2017


I have a type like

struct DistortedNoise<Source, Displacement> 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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170708/f5665a34/attachment.html>


More information about the swift-users mailing list