natToFin when there is evidence that the conversion will work

一曲冷凌霜 提交于 2019-12-05 10:19:47

You can do it directly by recursing on m, n, and the evidence for n `GT` m at the same time:

import Data.Fin

myNatToFin : (m : Nat) -> (n : Nat) -> {auto p : n `GT` m} -> Fin n
myNatToFin Z (S n) = FZ
myNatToFin (S m) (S n) {p = LTESucc _} = FS $ myNatToFin m n

Note that you need to pattern match on p in the second case (even though its value is not used on the right-hand side) so that the automatic argument for the recursive call can be filled in.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!