0

How can I write function like this

data Wrap : Nat -> Type where
  Wrp : n -> Wrap n

addOne : (n : Nat) -> Wrap (S n)
addOne {n} = Wrp (S n)

in a form like this

addOne : (n : Nat) -> S n
addOne {n} = S n

or something similar?

Thanks

R. Shirkhanov
  • 367
  • 3
  • 6
  • can you explain what you mean by "in a form like this"? What does that alternative form do? – joel Nov 02 '20 at 15:45

1 Answers1

1

addOne : (n : Nat) -> S n wouldn't be valid, as the return type wouldn't be a type, but a value. Closest thing to what you might want would be

addOne : (n : Nat) -> (k : Nat ** k = S n)
addOne n = (S n ** Refl)

where addOne would return a tuple of some Nat and a proof, that this Nat is indeed S n. Or proving that property afterwards:

addOne : (n : Nat) -> Nat
addOne n = S n

addOneIsSucc : (n : Nat) -> addOne n = S n
addOneIsSucc n = Refl
xash
  • 3,702
  • 10
  • 22