interface

Here is the C# Monad, where is the problem?

丶灬走出姿态 提交于 2020-02-24 00:52:52
问题 Reading a Previous SO Question I was confused to find Eric Lippert saying that an interface cannot be defined in C# for all Monads, using an implementation as below: typeInterface Monad<MonadType<A>> { static MonadType<A> Return(A a); static MonadType<B> Bind<B>(MonadType<A> x, Func<A, MonadType<B>> f); } My problem is all the problems listed in the question seem to have easy solutions: no "higher kinded types" => use parent interfaces no static method in interface. => why use static?! just

Here is the C# Monad, where is the problem?

一个人想着一个人 提交于 2020-02-24 00:49:32
问题 Reading a Previous SO Question I was confused to find Eric Lippert saying that an interface cannot be defined in C# for all Monads, using an implementation as below: typeInterface Monad<MonadType<A>> { static MonadType<A> Return(A a); static MonadType<B> Bind<B>(MonadType<A> x, Func<A, MonadType<B>> f); } My problem is all the problems listed in the question seem to have easy solutions: no "higher kinded types" => use parent interfaces no static method in interface. => why use static?! just

Here is the C# Monad, where is the problem?

天涯浪子 提交于 2020-02-24 00:49:28
问题 Reading a Previous SO Question I was confused to find Eric Lippert saying that an interface cannot be defined in C# for all Monads, using an implementation as below: typeInterface Monad<MonadType<A>> { static MonadType<A> Return(A a); static MonadType<B> Bind<B>(MonadType<A> x, Func<A, MonadType<B>> f); } My problem is all the problems listed in the question seem to have easy solutions: no "higher kinded types" => use parent interfaces no static method in interface. => why use static?! just

How to put an interface constraint on a generic method in C# 3.5?

雨燕双飞 提交于 2020-02-21 12:37:30
问题 I want to achieve something like this in C# 3.5: public void Register<T>() : where T : interface {} I can do it with class or struct, but how to do it with an interface? 回答1: C# and the CLR don't support overall interface constraints, although you can constrain it to a particular interface (see other answers). The closest you can get is 'class' and check the type using reflection at runtime I'm afraid. Why would you want an interface constraint in the first place? 回答2: If you are asking about

What is the benefit of using '--strictFunctionTypes' in Typescript?

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-21 10:56:02
问题 As I understand it, --strictFunctionTypes compiler option in Typescript prevents a very common use case of polymorphism from working: type Handler = (request: Request) => Response const myHandler: Handler = (request: Request & { extraArg: boolean }) => { return !!request.extraArg } Generally, I assume that all compiler options in the strict family have some great benefits, but in this case, all I see is that it prevents a very logical behavior from working. So what are the cases where this

What is the benefit of using '--strictFunctionTypes' in Typescript?

有些话、适合烂在心里 提交于 2020-02-21 10:55:54
问题 As I understand it, --strictFunctionTypes compiler option in Typescript prevents a very common use case of polymorphism from working: type Handler = (request: Request) => Response const myHandler: Handler = (request: Request & { extraArg: boolean }) => { return !!request.extraArg } Generally, I assume that all compiler options in the strict family have some great benefits, but in this case, all I see is that it prevents a very logical behavior from working. So what are the cases where this

What is the benefit of using '--strictFunctionTypes' in Typescript?

有些话、适合烂在心里 提交于 2020-02-21 10:55:06
问题 As I understand it, --strictFunctionTypes compiler option in Typescript prevents a very common use case of polymorphism from working: type Handler = (request: Request) => Response const myHandler: Handler = (request: Request & { extraArg: boolean }) => { return !!request.extraArg } Generally, I assume that all compiler options in the strict family have some great benefits, but in this case, all I see is that it prevents a very logical behavior from working. So what are the cases where this

How not to implement a function of an interface in class?

房东的猫 提交于 2020-02-20 05:33:21
问题 An interviewer asked me the following question in interview, but I don't know what could be the answer of this question, please help!!! What must be done if i don't want to implement a function in my class that is declared in an interface which is implemented by my class. Edited: I am using .NET with C#. It will be great if anyone can provide a sample code example in C#. Thanks 回答1: Implement the function, but throw an exception in the implementation. In .NET, you typically use one of the

How not to implement a function of an interface in class?

我怕爱的太早我们不能终老 提交于 2020-02-20 05:32:46
问题 An interviewer asked me the following question in interview, but I don't know what could be the answer of this question, please help!!! What must be done if i don't want to implement a function in my class that is declared in an interface which is implemented by my class. Edited: I am using .NET with C#. It will be great if anyone can provide a sample code example in C#. Thanks 回答1: Implement the function, but throw an exception in the implementation. In .NET, you typically use one of the

How not to implement a function of an interface in class?

时光怂恿深爱的人放手 提交于 2020-02-20 05:31:10
问题 An interviewer asked me the following question in interview, but I don't know what could be the answer of this question, please help!!! What must be done if i don't want to implement a function in my class that is declared in an interface which is implemented by my class. Edited: I am using .NET with C#. It will be great if anyone can provide a sample code example in C#. Thanks 回答1: Implement the function, but throw an exception in the implementation. In .NET, you typically use one of the