Skip to content
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

Language Support: Anonymous Derivations #1960

Closed
prasannavl opened this issue Apr 13, 2015 · 2 comments
Closed

Language Support: Anonymous Derivations #1960

prasannavl opened this issue Apr 13, 2015 · 2 comments
Assignees
Labels
Area-Language Design Feature Request Resolution-Duplicate The described behavior is tracked in another issue Verified

Comments

@prasannavl
Copy link

Anonymous derivation for classes and interfaces, providing the illusion of direct instantiation of interfaces, base classes, etc.

public interface IRandom {
 void SayHello();
 string GetString();
}

Its is impossible to use the existing new operator without colliding with current semantics. But introducing another keyword has its own problems, and compatibilities issues. Instead, simply use the new keyword, but as the constraint form, new() except that it takes an argument of syntax typeName { InitializationExpression } where the expression similar to the class initialization syntax, except that, all functions, are described as expressions.

new(IRandom { 
  SayHello = () => {
     Console.WriteLine("Hello!");
  },
  GetString = Func<string> => {
  return "Hello";
},
})

The Funcs aren't really funcs. They get translated into real methods by Roslyn. This is only used for the expression definition.

The above is a compile-time factor. This can also be extended to be done at run-time with a new overload, that takes a type as parameter, there-by providing the language with direct interface instantiation-like semantics.

@prasannavl prasannavl changed the title Language Support: Anonymous Derivatives Language Support: Anonymous Derivations Apr 13, 2015
@HaloFour
Copy link

This would be a dupe of #13 and #1728.

@gafter
Copy link
Member

gafter commented Apr 14, 2015

Closing as a dup of #13.

@gafter gafter closed this as completed Apr 14, 2015
@gafter gafter added the Resolution-Duplicate The described behavior is tracked in another issue label Apr 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Feature Request Resolution-Duplicate The described behavior is tracked in another issue Verified
Projects
None yet
Development

No branches or pull requests

5 participants