-
Notifications
You must be signed in to change notification settings - Fork 4
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
idea: interface validation #75
Comments
That's nice idea. I've been thinking about interface for a while and I was going to implement it like this: # `interface` is a reserved word so `protocol` is used instead.
protocol IFly:
proc fly() =
discard
class Bird impl IFly:
proc fly() =
echo "I'm flying!" and then it's converted below like nim-interface-implements: type IFly = tuple
fly: proc()
type Bird = ref object
proc fly(self: Bird) =
echo "I'm flying!"
proc toProtocol(self: Bird): IFly =
return (
fly: self.fly()
) I'm interested in your idea, but I can't think of a way to implement it. Can you tell me some details? |
I see. very nice. the syntax looks very clean and clear. The details need to be fleshed out. I am not sure it works.
so if we do:
perhaps it's a simple solution. maybe make it more explicit like: is that clearer now? None of the code was checked, it was just an idea. see if u can get it to work... Thanks! |
I see, I understand. |
I just created an issue based on this page. |
cool :-) |
Many people use interface as a design tool.
perhaps it is possible to use Nim's when compiles(...) feature
to expand something like checkImpl(myClass, ISomeInterface)
where ISomeInterface will be scanned (typetraits perhaps) for the public procs and fields, and then for each it will be checked in the (hidden by template) when compiles block. then we get a compiler error message, that this proc was not yet implemented.
What do you think of this idea? btw, very cool lib. just came across it!
The text was updated successfully, but these errors were encountered: