I have a very simple example, as a demonstration of how to use case _ of
that does not type check and I am not able to understand what the issue is:
data ZeroOrSign = Zero | Pos | Neg
sign : Ord elem => elem -> ZeroOrSign
sign x = case compare x 0 of
LT => Neg
EQ => Zero
GT => Pos
The function compare
is defined in Prelude, compare : Ord ty => ty -> ty -> Ordering
where Ordering
is just LT
, EQ
and GT
. The error I get is the following:
When checking right hand side of sign with expected type
ZeroOrSign
When checking an application of function Prelude.Interfaces.compare:
Ord elem is not a numeric type
If I try to define sign : Num elem => elem -> ZeroOrSign
then of course this creates issues as idris cannot find a function compare
defined for Num
types.
I am puzzled, any hint?