[racket] Typed Racket: verbose error message?

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri Feb 18 19:08:04 EST 2011

I think one thing that could help here is just changing the first
line.  It explicitly says "could not be applied to arguments", but
that's just false here.  The function memq can obviously be applied to
those arguments.  It just can't give the expected result type.  How
about "...can not be applied to given arguments to produce expected
result type", or something more like that?  That would be a big hint
that both inputs and outputs may be relevant.

Carl Eastlund

On Fri, Feb 18, 2011 at 6:56 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> I was working on the following snippet of code in Typed Racket:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (define-type InstructionSequence (U Symbol instruction-sequence))
>
> (define-struct: instruction-sequence ([needs : (Listof Symbol)]
>                                      [modifies : (Listof Symbol)]
>                                      [statements : (Listof Any)])
> #:transparent)
>
> (: registers-modified (InstructionSequence -> (Listof Symbol)))
> (define (registers-modified s)
>  (if (symbol? s) '() (instruction-sequence-modifies s)))
>
> (: modifies-register? (InstructionSequence Symbol -> Boolean))
> (define (modifies-register? seq reg)
>  (memq reg (registers-modified seq)))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> Typed Racket responded with a message that said:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> . Type Checker: Polymorphic function memq could not be applied to arguments:
> Argument 1:
>  Expected: a
>  Given:    Symbol
> Argument 2:
>  Expected: (Listof a)
>  Given:    (Listof Symbol)
>
> Result type:     (U (Listof a) False)
> Expected result: Boolean
>  in: (memq reg (registers-modified seq))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> It took me a long time to finally figure out that the error was trying
> to tell me that the result type was wrong, because the parts of the
> error message that was talking about Argument 1 and Argument 2
> distracted me from looking at the rest of the error message.  Can this
> be improved?
>
>
> (The fix to my code is to make sure the result is boolean by doing
> (and (memq ...) #t).
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
>



Posted on the users mailing list.