tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.03k stars 48 forks source link

Improve documentation/error reports for concept macros #79

Closed porky11 closed 8 years ago

porky11 commented 8 years ago

when trying to create concepts, i get messages "error: like no applicable concept macro found" this is not very helpful and I don't even get, how to define the correct concept-macros I'm not even able to (instantiate Array float 2)

isn't there a simpler way than concepts for such things? I thought about macro-dispatching on generic types like (def x (macro ((a (array-of 0 \))))), which may also be but maybe this won't be easyly implementable

tomhrr commented 8 years ago

On Thu, Sep 01, 2016 at 02:14:57PM -0700, Fabio Krapohl wrote:

when trying to create concepts, i get messages "error: like no applicable concept macro found" this is not very helpful and I don't even get, how to define the correct concept-macros I'm not even able to (instantiate Array float 2)

The error messages have been improved, and now show the concepts implemented by the arguments (including refinements), as well as the concepts expected by the concept macros that exist with that name. For example:

(import concepts)
(import array)

(def mys (struct intern ((a int) (b int))))
(std.concepts.implement Struct mys)
(std.concepts.instantiate Array mys 5)

yields:

test.dt:6:33: error: no applicable concept macro found (arguments implement the following concepts: Struct (refines Type); Value; current candidates accept: EqualityComparable, Value) (see macro at 6:1)
test.dt:6:1: error: macro expansion error (see previous)

When a concept macro is asserting the implementation of a concept outside the dispatch context, the required concept will now be included in the error message, too:

(import concepts)
(import array)
(import derivations)

(def mys (struct intern ((a int) (b int))))
(std.concepts.implement Struct mys)
(std.concepts.instantiate relations mys)
(std.concepts.implement EqualityComparable mys)
(std.concepts.instantiate Array mys 5)

yields:

test.dt:9:33: error: type does not implement concept LessThanComparable (see macro at 59:21)
.../array.dt:59:21: error: macro expansion error (see previous) (see macro at 1173:31)

isn't there a simpler way than concepts for such things? I thought about macro-dispatching on generic types like (def x (macro ((a (array-of 0 \))))), which may also be but maybe this won't be easyly implementable

Hopefully the error messages now are decent enough that alternatives don't seem so necessary, but I'm not inclined to add this sort of functionality into the core. Although there is a fair amount of ceremony required when defining new types, instantiating algorithms for types, and so on, this is necessary to some extent in any language. It seems like a relatively small cost for allowing the implementation to be completely library-based, given how much more complicated the core language would become if it had to handle functions with generic types and concept (or type class or similar) definitions.