[swift-evolution] Add "maybe" keyword / Explicit Support for Ternary Logic

davesweeris at mac.com davesweeris at mac.com
Thu Jan 7 20:16:40 CST 2016


Oh! I hadn’t considered a non-deterministic option. That’s interesting…

To answer your question, though, I was referring to a trivalent type. Mostly I just think it’d be nice to have the keyword coloring for “maybe”.

> On Jan 7, 2016, at 18:10, Developer <devteam.codafi at gmail.com> wrote:
> 
> I’m not sure I understand what you intend to do here.  If you mean to introduce a non-determinism type, that’s what the list monad is for.  If you want true trivalent logic, then the type Tern you describe is precisely the type that it corresponds to.
> 
> 
>> On Jan 7, 2016, at 7:03 PM, Dave via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Does anyone else occasionally do stuff like this?
>> typealias Tern = Bool?
>> let maybe:Tern = nil
>> 
>> Personally, I’ve only needed it a couple times, but it seems like it could be useful. Maybe Tern should be its own enum instead of a typealias. 
>> Either way, aesthetically speaking, it’d be nice to have “maybe” be colored the same as “true” and “false”.
>> 
>> I’m not sure if there’s a generally agreed-upon ternary truth-table, especially for code like:
>> 	if maybe == true {
>>>> 	} else {
>>>> 	}
>> 
>> (Come to think of it, didn’t someone suggest abandoning:
>> 	if something == something_else {
>>>> 	} else {
>>>> 	}
>> in favor of:
>> 	switch (something == something_else) {
>> 	case true: …
>> 	case false: …
>> 	}
>> If so, that’d clean up the syntax since switches have to be exhaustive anyway… If a comparison results in a Tern you need to have a maybe case, if it results in a Bool you don’t.
>> 
>> 
>> 
>> Anyway, thoughts?
>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 



More information about the swift-evolution mailing list