I wish to create a class of types for which one can prove a certain element is positive or negative, or zero. I have created an interface:
interface Signed t where
data Positive : t -> Type
data Negative : t -> type
data IsZero : t -> Type
Now I'd like to create an implementation for Nat
, but I can't work out the syntax for it. This for instance does not work:
Signed Nat where
data Positive : Nat -> Type where
PosNat : (n : Nat) -> Positive (S n)
data Negative : Nat -> Type where
NegNat : Void -> Negative Nat
data IsZero : Nat -> Type
ZZero : IsZero Z
I get not end of block
error where data Positive
stands in the implementation. Omitting data Positive...
line, however, does not work either. Idris then says that method Positive is undefined
. So how do I implement a type inside an interface?
Also the following does not seem to work:
data NonZero : Signed t => (a : t) -> Type where
PositiveNonZero : Signed t => Positive a -> NonZero a
NegativeNonZero : Signed t => Negative a -> NonZero a
With Idris saying: Can't find implementation for Signed phTy
. So what's the correct syntax to do all this? And perhaps I'm doing it the wrong way? I'm aware of the existence of Data.So
, but after a few experiments it seems complicated to me and I'd prefer to work with manually defined proofs, which is a lot simpler. Besides the doc for Data.So
states itself that it should really be used with primitives.