Uploaded image for project: 'core.typed'
  1. CTYP-297

Allow defmulti without expected type

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Completed
    • Affects versions: None
    • Fix versions: 0.5.0
    • Components: None
    • Labels:
      None

      Description

      Problem

      defmulti expressions need an expected type at the moment. This is annoying and we can do better.

      This should type check without issues.

      (defmulti f identity)
      

      Solution

      Remove the restriction on a MultiFn requiring an expected type. This raises the question of how to infer the type of a multimethod based only on its dispatch function.

      Here is the new scheme:

      If the dispatch function is a function type

      [b ... b -> c]
      

      the entire multimethod is of type

      [b ... b -> Any]
      

      That is, infer the type of the dispatch function, and replace the return types with Any.

      eg.

      (defmulti f identity)
      

      Dispatch function is of type

      (All [x] [x -> x :object {:id 0}])
      

      Multimethod annotated as:

      (All [x] [x -> Any])
      

      Filters and objects should be deleted from the dispatch function to generate the multimethod annotation.

      Pull request: 83
      Commit:
      Version:

        Attachments

          Activity

            People

            • Assignee:
              ambrosebs Ambrose BS
              Reporter:
              ambrosebs Ambrose BS
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: