racket-collections icon indicating copy to clipboard operation
racket-collections copied to clipboard

unclear on reason for `gen:indexable` arity error

Open mbutterick opened this issue 7 years ago • 5 comments

This will work:

#lang racket
(require data/collection)
(struct wrapped-collection (value)
    #:methods gen:countable
     [(define (length c) 42)])

(length (wrapped-collection 'foo)) ; 42

But remove the c from the definition of length, and it won't:

#lang racket
(require data/collection)
(struct wrapped-collection (value)
    #:methods gen:countable
     [(define (length) 42)])

And the error message makes sense — length expects one argument, and we removed it:

git/racket/racket/collects/racket/private/generic.rkt:523:0: gen:countable: generic method definition
 has an incorrect arity; expected a procedure that accepts 1 argument
  length: #<procedure:length>

Now consider this example, with gen:indexable:

#lang racket
(require data/collection)
(struct wrapped-collection (value)
    #:methods gen:indexable
     [(define (ref c i) 42)])

It immediately triggers a similar arity error:

git/racket/racket/collects/racket/private/generic.rkt:523:0: gen:indexable: 
generic method definition has an incorrect arity; expected a procedure that 
accepts 1 or more arguments
  ref: #<procedure:ref>

But why? ref does in fact accept the right number of arguments.

mbutterick avatar Jun 28 '17 01:06 mbutterick