> On Nov 22, 2017, at 2:59 PM, Mike Kluev <[email protected]> wrote:
>
> on Date: Tue, 21 Nov 2017 22:54:21 -0800 Douglas Gregor <[email protected]
> <mailto:[email protected]>> wrote:
>
> > On Nov 21, 2017, at 10:48 PM, David Hart <[email protected]
> > <mailto:[email protected]>> wrote:
> >
> > On 22 Nov 2017, at 07:41, Douglas Gregor via swift-evolution
> > <[email protected] <mailto:[email protected]>
> > <mailto:[email protected] <mailto:[email protected]>>>
> > wrote:
> >
> >>
> >> I think it’s straightforward and less ugly to make structural types allow
> >> extensions and protocol conformances.
> >
> > Can somebody explain to me what is less ugly about that? I would have
> > naturally thought that the language would be simpler as a whole if there
> > only existed nominal types and all structural types were just sugar over
> > them.
>
> See Thorsten’s response with, e.g.,
>
> Function<Double, InoutParam<String>, Param<Int>>
>
> which handles “inout” by adding wrappers around the parameter types (which
> one would have to cope with in any user of Function), but still doesn’t
> handle argument labels. To handle argument labels, we would need something
> like strings as generic arguments. We’d also need to handle calling
> conventions and anything else we invent for function types.
>
>
> can you outline how extensions and protocol conformances might look for
> structural types? to compare the ugliness of both approaches.
There are some examples at
https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#extensions-of-structural-types
e.g., making all tuples of Equatable elements Equatable (which also mixes in
conditional conformances and variadic generics):
extension<...Elements : Equatable> (Elements...) : Equatable { //
extending the tuple type "(Elements...)" to be Equatable
}
One could imagine adding a “curry” operation to function types:
extension<Param1, Param2, Result> (Param1, Param2) -> Result {
var curried: (Param1) -> (Param2) -> Result {
return { (arg1: Param1) in { (arg2: Param2) in self(arg1, arg2) } }
}
}
Or perhaps making metatypes Hashable so they can be used as keys into a
Dictionary:
extension<T> T.Type: Hashable {
var hashValue: Int {
return ObjectIdentifier(self).hashValue
}
static func ==(lhs: T.Type, rhs: T.Type) -> Bool { /* standard library magic
*/ }
}
- Doug
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution