Skip to content

Suggestion: how about & for overloaded method type separator, instead of |? #566

@vain0x

Description

@vain0x

Current syntax of overloaded method type looks like a union of function types. However, type of overloaded method behaves like an intersection of function types in typical type system.

I suggest to change the separator from | to & for consistency.


For example, there is a method f that is overloaded like this:

def f: (Integer) -> void
     | (String) -> void

If f has an intersection of function types, type check of f 42 passes like this:

f: ((Integer) -> void) & ((String) -> void)
-------------------------------------------
f: (Integer) -> void                         42: Integer
--------------------------------------------------------
f 42: void

f "hello" is also okay.

If union, it doesn't. It's unsure whether f can take an integer. This is an example written in lambda calculus with subtyping:

# g: (String) -> void
let g = \s: String. use_string s in

# Upcast to union type. This is OK since (T | U) is subtype of T.
let f: ((Integer) -> void | (String) -> void) = g in

f 42  # This shouldn't pass type check since `g 42` is type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions