English 中文(简体)
替换Coq清单中的内容
原标题:Replace element in Coq list
最佳回答

If you want to apply the same function to every element of a list, you can use map. Instead if you want to only replace one single element of a list, you may need to write your own replace function. For example:

Require Import List.
Import ListNotations.

Fixpoint replace {A : Type} (l : list A)  (i : nat) (v : A) := 
  match l with 
  | [] => []
  | a :: l1 => match i with 
               |    0 => v :: l1 
               | S i1 => a :: replace l1 i1 v 
               end 
  end.

Compute replace [true; false; true] 2 false.
问题回答

Coq采用功能式方案拟订模式,因此,你不能“取代”一种你用必要的方案拟订语言编写的要素。 但是,你可以制定一份新名单,其要素为:i, 即f (v[i], 而不是(old)v[i], 所有其他内容与原始名单相同。

请注意,数学比较<代码>seq.v的图书馆已经提供了准确的<代码>_nth功能。





相关问题
What are the differences between NP, NP-Complete and NP-Hard?

What are the differences between NP, NP-Complete and NP-Hard? I am aware of many resources all over the web. I d like to read your explanations, and the reason is they might be different from what s ...

Implementation Detail for Graph Analysis Algorithms

Let s say I have a graph with "heavy" nodes, that is each node is an object that is already carrying a lot of data. I want to do a graph transformation that requires me to calculate a special ...

Worst case running time (Big O)

I have this question, and I don t know how to solve it, because I don t understand it. :( The question is: Programs A and B are analyzed and are found to have worst case running times no ...

RSA cryptosystem

Hi i am trying to set up an RSA cryptosystem i have all the values except d selected prime numbers: p=1889, q=2003, n=3783667, phi=3779776, e= 61 i got stuck finding d could anyone help me to figure ...

BNF Grammar Derivation

I want to apply rules of BNF Grammar to produce derivation for : a_Num

热门标签