Keno Fischer
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
4
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
The purpose of this document is to serve as a focused basis of discussion for the design of an interfaces system for Julia. It is intended to capture the outcome of several discussions I've had with different groups of people over the past few months. The design described herein is intended to be the minimal basis on which to build further. It does not capture everything that everyone wants to do, but hopefully it captures a common sense of what most people agree on is a reasonable place to start. # Guiding Principles The first question to answer here is what the purpose of an interface system is. There are differing opinions on this and different goals, but I think the most pressing issue is what I like to call the "compositional whodunnit". What I mean by that is that when composing different packages providing abstract functionality, it is easy to run into situations where something breaks due to leaky abstractions. In such situations, it is extremely hard to differentiate between: 1. A bug in the package providing the interface 2. A bug in the package using the interface 3. A fundamental disagreement on what the interface is supposed to mean This becomes expontentially more difficult the more packages and interfaces are involved, and as such issues of this nature often require triage by developers familiar with large fractions of the ecosystem. In some ways, the fundamental problem here is a lack of documentation. We do not have a practice of writing down what our interfaces are, so even those who wish to write code against an interface are generally unable to do so. In my personal opinion, this is the major part of problem and an opinionated and structured format for documenting interface expectations and requirements is already 90% of a solution, though we can and should of course try to do better still. That said (and I think this is the main point of my argument), because of this, to the extent that there is a conflict between the ability to clearly specify an interface and the ability to check that a particular implementation satisfies an interface, we should err on the side of expressability, rather than verification. This is in some sense the exact opposite trade off that static languages take, where the expressivity is exactly the expressivity of the interface. With these thoughts in mind, I would like to propose the following set of principles: 1. (Formal) verification is great, but should not get in the way of expressivity. 2. An initial solution should be a Test-extension, not a semantic change to the language 3. Provide tooling to assist the user in detecting interface violations *in a particular instance* # An implementation roadmap Based on various discussions, I think we should being with interfaces that are simple list of methods (and in an immediate second step their return types). The initial semantics of an interface would be that an interface is deemed satisfied if, for the given type, it is not possible for the signature to throw a MethodError. As a notional syntax, we might consider: ``` @interface Indexable T->begin getindex(::T, ::Int) end @interface HasLength T->begin length(::T)::Int end ``` The reason for choosing the absence of a MethodErorr, rather than a weaker notion like method existence is that it bootstraps more nicely to correctness checking users of an interface. For example, we might have a function like: ``` function get_all(x) for i = 1:length(x) x[i] end end ``` We could have a function like (again, syntax notional) `check(get_all, Length | Indexable)` that would go through and check, whether (under the assumption that the methods of the interfaces themselves do not throw method errors), the function get_all can throw a method error. In particular, this would then allow for interface composition. An additional important consideration is that we have the ability (as of last year - added precisely for this purpose) to ask the compiler to check whether a given signature has the possiblity to throw a MethodError, as well as the ability to provide nice user-facing printing of such analysis (using JET). I thus propose the following roadmap: 1. Ability to specify/check a list of methods (no return types) - Implemented by asing whether `MethodError` is in the compilers inferred exctype 2. Ability to check an implementation against an interface - Implemented by giving JET an overlay method table and asking the same question 3. Add return types to the above - Should be a trivial addition to 2, but a separate feature 4. Design a system to associate interfaces with abstract types - Some thoughts below, but to be designed 5. Write interfaces for Base and see how things work out 6. Integrate interfaces into Base's existing `MethodError` error hinting. Importantly, none of these require additions to base (with the possible exception of step 2, which is supported in principle, but nobody has every really tried). That said, I know that this is not powerful enough to implement many of the different kinds of interfaces that people want, for example, dependent return types `getindex(::T, ::Int)::eltype(T)`, value constraints `length(size(T)) == ndims(T)`, etc. Those additions are comptabile with this notion of interfaces, but are deliberately excluded from the MVP because they are harder to do. # Thoughts on associating interfaces with abstract types I propose that we use method tables for type-interface association. The reason for this is that julia programmers are already used to thinking about method tables and how they merge between different packages. An example way to do this might be to say something like (syntax notional): ``` Interfaces.shoud_satisfy(Indexable)(::AbstractArray) = true ``` Then a macro like `@check_all_interfaces(MyPackage)` would go through and ask the compiler to check all interfaces declared as above in `MyPackage`. Importantly, a definition like this would allow opt out for special snowflake types like: ``` # Does not satisfy the interface because it does not return `Int`, even though it is an AbstractArray. Interfaces.shoud_satisfy(HasLength)(::SymbolicArray) = false ``` In addition, we could adjust the `MethodError` handler to give more informative error message when a concrete interface violation is detected (however, this is trickier than it may seem, because the MethodError being thrown may not necessarily be the one that violates the interface itself (rather the fact of a MethodErorr being thrown there could violate some interface higher in the stack) - so I would suggest punting on this for now). # Is this the same as traits? Traits and interfaces are somewhat orthogonal. To my mind, the biggest differences is that for traits people generally want to be able to use them to affect the runtime semantics of the program. This proposal does not do that. However, it is of course possible to use any of the existing trait systems and use this proposal to specify their semantics. The biggest issue for a dedicated traits system is that I don't think there is sufficient design space between what is current achievable with traits using macros (esp when enhanced with this proposal) and the place where you start wanting a compiler to do algorithmic selection for you (which needs a completely seprate mechanism). That said, we can revisit that question at a later time.

Import from clipboard

Paste your webpage below. It will be converted to Markdown.

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template is not available.
Upgrade
All
  • All
  • Team
No template found.

Create custom template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

How to use Slide mode

API Docs

Edit in VSCode

Install browser extension

Get in Touch

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

No updates to save
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully