Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subclass constraints and fundeps not checking right? #1050

Open
stylewarning opened this issue Jan 21, 2024 · 0 comments
Open

subclass constraints and fundeps not checking right? #1050

stylewarning opened this issue Jan 21, 2024 · 0 comments
Labels
bug Something isn't working type system The Coalton type system

Comments

@stylewarning
Copy link
Member

I'm not 100% sure if my diagnosis is correct below, but I think this is an error.

I was doing some work splitting a type class and got to a situation where I believe some constraints are unambiguous, but Coalton considered them ambiguous:

(coalton-toplevel
  (define-class (RandomAccessBase :f :t (:f -> :t))
    (make (UFix -> :t -> :f))
    (length (:f -> UFix)))

  (define-class (RandomAccessBase :f :t => RandomAccessReadable :f :t (:f -> :t))
    (unsafe-set! (:f -> UFix -> :t -> Unit)))

All is good and well, and now we want to implement a function on RandomAccessReadable.

(coalton-toplevel
  (declare aref (RandomAccessReadable :f :t => :f -> UFix -> (Optional :t)))
  (define (aref storage index)
    (if (and (<= 0 index) (< index (length storage)))
        (Some (unsafe-aref storage index))
        None))

With the declaration, we get an error:

;     error: Explicit type is missing inferred predicate
;     --> blah:70:11
;       |
;    70 |    (define (aref storage index)
;       |             ^^^^ Declared type RANDOMACCESSREADABLE :A :B ⇒ (:A → UFIX → (OPTIONAL :B)) is missing inferred predicate RANDOMACCESSBASE :A :C
;   
;   
;     (in form starting at line: 68, column: 0, position: 2795)

Without the declaration, Coalton infers the following:

COALTON-USER> (type-of 'aref)
∀ :A :B :C. (RANDOMACCESSBASE :A :B) (RANDOMACCESSREADABLE :A :C) ⇒ (:A → UFIX → (OPTIONAL :C))

Since the functional dependency forces :b given :a, Coalton is mistakenly not unifying (?) :b and :c.

@stylewarning stylewarning added bug Something isn't working type system The Coalton type system labels Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working type system The Coalton type system
Projects
None yet
Development

No branches or pull requests

1 participant