5

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
Shersh
  • 9,019
  • 3
  • 33
  • 61
Attila Karoly
  • 951
  • 5
  • 13

2 Answers2

3

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:

  1. Old discussion.
  2. Some similar question.
  3. Some similar issue on GitHub.

UPDATE:

Finally found more relevant question with answer:

Why is typecase a bad thing?

Shersh
  • 9,019
  • 3
  • 33
  • 61
1

You can in fact now do this in Idris 2:

fnc : Type -> Integer
fnc Bool = 1
fnc Nat = 2
fnc _ = 3
Matt R
  • 9,892
  • 10
  • 50
  • 83