[Agda] pattern matching order

Thorsten Altenkirch Thorsten.Altenkirch at nottingham.ac.uk
Mon Apr 3 15:08:53 CEST 2017


Hi,

I tried to define the following function by pattern matching

codeDouble : ∀{n : ℕ} → Bool × Fin n → Fin (double n)
codeDouble {zero} (b , ())
codeDouble {suc n} (false , zero) = zero
codeDouble {suc n} (true , zero) = suc zero
codeDouble {suc n} (b , suc x) = suc (suc (codeDouble (b , x)) )

But to my confusion the term "codeDouble {suc n} (b , suc x) “ didn’t reduce. This can be fixed by changing the order

codeDouble : ∀{n : ℕ} → Bool × Fin n → Fin (double n)
codeDouble {zero} (b , ())
codeDouble {suc n} (b , suc x) = suc (suc (codeDouble (b , x)) )
codeDouble {suc n} (false , zero) = zero
codeDouble {suc n} (true , zero) = suc zero

I guess I can answer this myself: since I first match on the boolean agda decides also to do case analysis first on the boolean and then on the Fin which duplicates my last line and has the effect that the defining equality doesn’t hold definitionally (this is always a bit agda). In this case agda could have matched my definition by changing the order. Is this too much to ask for?

Cheers,
Thorsten




This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.chalmers.se/pipermail/agda/attachments/20170403/11a26eb3/attachment-0001.html>


More information about the Agda mailing list