ambiguous-call

Ambiguous occurrence in Haskell with “show”

好久不见. 提交于 2019-12-02 06:36:58
I'm new in functional programming and I'm trying to create and show a Stack with Haskell. I'd like my program to show me the Stack I'm building with it. This is my code: module Stack (Stack, empty, push, pop, top, isEmpty) where data Stack a = EmptyStack | Stk a (Stack a) push x s = Stk x s top (Stk x s) = x pop (Stk _ s) = s empty = EmptyStack isEmpty EmptyStack = True isEmpty (Stk x s) = False` instance Show a => Show (Stack a) where show EmptyStack = "|" show (Stk a b) = (show a) ++ " <- " ++ (show b) With "show (push 1 empty)" I'd expect an answer (more or less) like: " 1 <- | " But I'm

Question about ambiguous calls in C#

百般思念 提交于 2019-12-01 15:53:54
I have a question that's not really a problem, but something that made me a little curious. I have a class with two methods in it. One is a static method and the other one is an instance method. The methods have the same name. public class BlockHeader { public static BlockHeader Peek(BinaryReader reader) { // Create a block header and peek at it. BlockHeader blockHeader = new BlockHeader(); blockHeader.Peek(reader); return blockHeader; } public virtual void Peek(BinaryReader reader) { // Do magic. } } When I try to build my project I get an error saying: The call is ambiguous between the

How to resolve ambiguity when argument is null?

那年仲夏 提交于 2019-11-30 00:21:20
问题 Compiling the following code will return The call is ambiguous between the following methods or properties error. How to resolve it since I can't explicitly convert null to any of those classes? static void Main(string[] args) { Func(null); } void Func(Class1 a) { } void Func(Class2 b) { } 回答1: Func((Class1)null); 回答2: You could also use a variable: Class1 x = null; Func(x); 回答3: Cast null to the type: Func((Class1)null); 回答4: Using as for the casting makes it slightly more readable with the

Avoiding an ambiguous match exception

时光怂恿深爱的人放手 提交于 2019-11-28 17:20:54
I am invoking a static method Parse on a type via reflection because I do not know the type of the object at compile-time (I do know, however, it has a Parse method, taking a string). However, I am getting an ambiguous match exception, presumably because there are a lot of overloaded Parse methods each taking a single object (string, int, double etc.). How can I be more specific in my method invocation to ensure I reach the correct method ( Parse(string s) ) and the exception is not thrown. My code looks like this: Type returnType = p.PropertyType; object value = returnType.GetMethod("Parse")

Why does the most negative int value cause an error about ambiguous function overloads?

房东的猫 提交于 2019-11-27 03:54:33
I'm learning about function overloading in C++ and came across this: void display(int a) { cout << "int" << endl; } void display(unsigned a) { cout << "unsigned" << endl; } int main() { int i = -2147483648; cout << i << endl; //will display -2147483648 display(-2147483648); } From what I understood, any value given in the int range (in my case int is 4 byte) will call display(int) and any value outside this range will be ambiguous (since the compiler cannot decide which function to call). It is valid for the complete range of int values except its min value i.e. -2147483648 where compilation

Avoiding an ambiguous match exception

青春壹個敷衍的年華 提交于 2019-11-27 00:25:18
问题 I am invoking a static method Parse on a type via reflection because I do not know the type of the object at compile-time (I do know, however, it has a Parse method, taking a string). However, I am getting an ambiguous match exception, presumably because there are a lot of overloaded Parse methods each taking a single object (string, int, double etc.). How can I be more specific in my method invocation to ensure I reach the correct method ( Parse(string s) ) and the exception is not thrown.