am hoping some Haskell experts can help clarify something.
Is it possible to define Nat
in the usual way (via @dorchard Singleton types in Haskell)
data S n = Succ n
data Z = Zero
class Nat n
instance Nat Z
instance Nat n => Nat (S n)
(or some variant thereof) and then define a LessThan
relation
such that forall n
and m
LessThan Z (S Z)
LessThan n m => LessThan n (S m)
LessThan n m => LessThan (S n) (S m)
and then write a function with a type like:
foo :: exists n. (LessThan n m) => Nat m -> Nat n
foo (S n) = n
foo Z = foo Z
I explicitly want to use the "LessThan" in the output type for foo
,
I realize that one could certainly write something like
foo :: Nat (S n) -> Nat n
but thats not what I'm after.
Thanks!
Ranjit.