Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Proof-of-concept implementation of Static Structural #9

Closed
wants to merge 1 commit into from

Conversation

saeta
Copy link
Contributor

@saeta saeta commented Jul 31, 2020

Based on explorations of structural generic programming in
tensorflow/swift-models#650 we would like to support
smooth interactions between KeyPaths and structural generic programming.
Based on discussions with @shabalind, I have put together a quick
proof-of-concept demonstrating how to unify a "static structural"
implementation with the "instance"-level structural generic programming we
have been exploring so far.

This is definitely an incomplete implementation, but this would allow us to
easily implement KeyPathIterable and its ilk on top of structural generic
programming (something not possible previously), in addition to unifying with
the existing KeyPath world.

There are a couple further extensions:

  1. Solution for HNil To use a proper cons-list construction, this will
    require a bottom type (Never) that conforms to every protocol, and
    multiple conformances. Alternatively, an encoding that appears to work
    is a cons-list construction that doesn't use a special end type.
  2. Typealias inference: Swift does not currently infer typealiases for
    these kinds of derived conformances.
  3. Enum support This current implementation doesn't include enum support
    although this is straight forward to add.
  4. Simplier structural representations: When the single static structural
    derived conformance, we can easily implement multiple simpler "structural"
    encodings (e.g. a simple Cons-list of values in addition to the current
    structural representation).
  5. Extensions to KeyPaths could enable StaticStructural to simply be the key
    paths themselves. (i.e. if you could retrieve the field name corresponding
    to the key path.)

Based on explorations of structural generic programming in
tensorflow/swift-models#650 we would like to support
smooth interactions between KeyPaths and structural generic programming.
Based on discussions with @shabalind, I have put together a quick
proof-of-concept demonstrating how to unify a "static structural"
implementation with the "instance"-level structural generic programming we
have been exploring so far.

This is definitely an incomplete implementation, but this would allow us to
easily implement KeyPathIterable and its ilk on top of structural generic
programming (something not possible previously), in addition to unifying with
the existing KeyPath world.

There are a couple further extensions:

 1. **Solution for `HNil`** To use a proper cons-list construction, this will
    require a bottom type (`Never`) that conforms to every protocol, and
    multiple conformances. Alternatively, an encoding that appears to work
    is a cons-list construction that doesn't use a special end type.
 2. **Typealias inference**: Swift does not currently infer typealiases for
    these kinds of derived conformances.
 3. **Enum support** This current implementation doesn't include enum support
    although this is straight forward to add.
 4. **Simplier structural representations**: When the single static structural
    derived conformance, we can easily implement multiple simpler "structural"
    encodings (e.g. a simple Cons-list of values in addition to the current
    structural representation).
 5. Extensions to KeyPaths could enable StaticStructural to simply be the key
    paths themselves. (i.e. if you could retrieve the field name corresponding
    to the key path.)
@saeta
Copy link
Contributor Author

saeta commented Jul 31, 2020

CC @shabalind @dabrahams @dan-zheng

@shabalind
Copy link
Contributor

Closing this off for now similarly to #10. We might revisit it later.

@shabalind shabalind closed this Sep 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants