typecase

Pattern matching on Type in Idris

会有一股神秘感。 提交于 2019-12-23 18:04:17
问题 Probably it's elementary but I don't understand why the following function answers 1 for fnc Nat and also, for fnc Integer , which is not even included as a pattern. fnc : Type -> Integer fnc Bool = 1 fnc Nat = 2 回答1: You can't pattern match on type and you shouldn't. When I compile your code I receive next error: warning - Unreachable case: fnc Nat This was already discussed earlier: Old discussion. Some similar question. Some similar issue on GitHub. UPDATE: Finally found more relevant

Finding maximum value of a short int variable in C

一笑奈何 提交于 2019-12-06 05:50:05
问题 I was working on Exercise 2-1 of K&R, the goal is to calculate the range of different variable types, bellow is my function to calculate the maximum value a short int can contain: short int max_short(void) { short int i = 1, j = 0, k = 0; while (i > k) { k = i; if (((short int)2 * i) > (short int)0) i *= 2; else { j = i; while (i + j <= (short int)0) j /= 2; i += j; } } return i; } My problem is that the returned value by this function is: -32768 which is obviously wrong since I'm expecting a