tomhrr / dale

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

Concept macros should not return true #81

Closed porky11 closed 8 years ago

porky11 commented 8 years ago

Some concept macros don't require something to be implemented like Type and Struct Because some concept macros using structs ask information about the structs it should be possible to check, if the argument isn't a struct, in the concept macro already, for example.

tomhrr commented 8 years ago

On Mon, Sep 05, 2016 at 01:30:53PM -0700, Fabio Krapohl wrote:

Some concept macros don't require something to be implemented like Type and Struct Because some concept macros using structs ask information about the structs it should be possible to check, if the argument isn't a struct, in the concept macro already, for example.

I'm not sure I understand the suggestion. The main concept macros that use structs are the =, !=, and relations concepts in the derivations library, but those already require that the type parameter implement the Struct concept.

porky11 commented 8 years ago

the concepts Type and Struct for example can be implemented for anything, but if some type isn't a struct. When I try to implement the relations concepts for objects, that are no structs, but implement the struct concept, the error will be recognized during the macroexpansion, not before, what concept macros are for, and so implementing Struct for something is useless, because it won't yield errors anyway

tomhrr commented 8 years ago

On Wed, Sep 07, 2016 at 10:43:20PM -0700, Fabio Krapohl wrote:

the concepts Type and Struct for example can be implemented for anything, but if some type isn't a struct. When I try to implement the relations concepts for objects, that are no structs, but implement the struct concept, the error will be recognized during the macroexpansion, not before, what concept macros are for, and so implementing Struct for something is useless, because it won't yield errors anyway

OK, I think I see what you mean now. However, on trying to implement the struct concept for a non-struct type, I get the following:

user@host:$ cat test.dt
(import concepts)

(std.concepts.implement Struct int)
user@host:~$ dalec test.dt
test.dt:3:32: error: argument is not a struct (see macro at 315:26)
/home/tomh/work/dale/modules/concepts-core.dt:315:26: error: macro expansion error (see previous) (see macro at 3:1)
user@host:~$

Can you post an example program where a non-struct type is able to implement the Struct concept?