[swift-evolution] [Returned for revision] SE-0077: Improved operator declarations

L Mihalkovic laurent.mihalkovic at gmail.com
Fri Jun 24 12:00:59 CDT 2016


Swift is all about values and protocols, so I was thinking about smthg like this:

enum OperatorAssociativity { case left, right }
enum PrecedenceGroup {
    casedefaultGroup(OperatorAssociativity)
    indirect case strongerThan(OperatorAssociativity,PrecedenceGroup)
    indirect case weakerThan(OperatorAssociativity,PrecedenceGroup)
    indirect case between(OperatorAssociativity, strongerThan: PrecedenceGroup, weakerThan: PrecedenceGroup)
}

let Additive: PrecedenceGroup = .defaultGroup(.left)
let Multiplicative: PrecedenceGroup = .strongerThan(.left, Additive)
let Exponentiative: PrecedenceGroup = .strongerThan(.left, Multiplicative)
let SomeOtherGroup: PrecedenceGroup = .between(.right, strongerThan: Multiplicative, weakerThan: Exponentiative)


standard Swift, which makes it easier to reflect when the api gets created in 4.0

Regards
LM
(From mobile)


> On Jun 24, 2016, at 2:47 PM, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> 
> L. Mihalkovic via swift-evolution <swift-evolution at ...> writes:
> 
>>> Could you please explain what you mean by "meta-circular syntax for 
> the 
>>> precedence group definitions"? An example?
>> =define it using existing swift constructs rather than by extending 
> swift with new kwd looks like grp
>> matches a struct. 
> 
> I still don't fully understand without an example :(
> If you mean something like this:
> 
> protocol PrecedenceGroup_Additive {
>    associatedtype StrongerThan_Comparative
>    associatedtype WeakerThan_Multiplicative
> }
> 
> Then this is just ugly.
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160624/29efe2f2/attachment.html>


More information about the swift-evolution mailing list