Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

idris - Why can (and must) the variable x appear twice on the left side of the function definition? And what's the meaning?

I'm a green hand with Idris,and get confused with this definition, as I don't understand how it works. The definitionare as follows.

sameS : (k : Nat)->(j : Nat)->(k = j)->((S k) = (S j))
sameS x x Refl=Refl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Let us start by breaking down the type signature:

sameS : (k : Nat) -> (j : Nat) -> (k = j) -> ((S k) = (S j))

sameS is a function. sameS take the following arguments:

  1. (k : Nat) a parameter k of type Nat
  2. (j : Nat) a parameter j of type Nat
  3. (k = j) A proof that k and j are equal

sameS returns:

((S k) = (S j)) proof that S k and S j are equal.

Now let us breakdown the definition:

sameS x x Refl = Refl

The type of Refl is a = a.

x is both the first and second argument because both are identical. We know this because the 3rd argument is Refl.

Refl is returned because S x = S x.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...