简体   繁体   English

谁能解释ZF表达式的第二条归约规则?

[英]Can anyone explain the second reduction rule for ZF-expressions?

[ e | v <- f:fs, q ] [ e | v <- f:fs, q ] reduces to [ e | q ] [ v := f ] ++ [ e | v <- fs, q ] [ e | v <- f:fs, q ]减少为[ e | q ] [ v := f ] ++ [ e | v <- fs, q ] [ e | q ] [ v := f ] ++ [ e | v <- fs, q ]

The output of [ e | v <- f:fs, q ] [ e | v <- f:fs, q ]的输出 [ e | v <- f:fs, q ] should be a single list. [ e | v <- f:fs, q ]应该是一个列表。 What does it mean to put two lists together in the reduction? 将两个列表放在一起表示什么意思? I mean you can't just put two lists together like this ["a"]["b"] . 我的意思是您不能像这样["a"]["b"]仅仅将两个列表放在一起。

Also, is the symbol := the same as = ? 另外,符号:=是否等于=

Without knowing where you've seen this it's hard to know for certain what is meant. 不知道您在哪里看到过它,很难确定是什么意思。 [e | q][v := f] [e | q][v := f] is not valid Haskell code (barring some creative use of language extensions). [e | q][v := f]无效 Haskell代码(除了一些创造性地使用语言扩展的)。

What is probably meant is something more like 可能意味着更像

[e' | q'] ++ [e | v <- fs, q]

where e' is e with all instances of v in replaced with f , and q' is q with all instances of v replaced with f 其中e'e ,其中v所有实例v f替换,而q'qv所有实例v f替换

So, for example if f was 5, e was v*2 and q was odd v we'd have 因此,例如,如果f为5,则ev*2qodd v

[v*2 | v <- 5:fs, odd v]

Which would reduce to 这将减少到

[5*2|odd 5] ++ [v*2 | v <- fs, odd v]

Since odd 5 reduces to True we end up with 由于odd 5减少为True我们最终得到

[5*2] ++ [v*2 | f<- fs, odd v]

The notation you mention is not Haskell code, but a meta-notation for substitution which is frequently used in programming languages theory. 您提到的符号不是Haskell代码,而是用于替换的元符号,该符号在编程语言理论中经常使用。

If e and t are Haskell expressions, and x is a Haskell variable, we write e [x := t] to denote the expression e where all the free occurrences of x have been replaced with t (and avoiding captures). 如果et是Haskell表达式,并且x是Haskell变量,我们将e [x := t]表示为表达式e ,其中x所有自由出现都已被t替换(并避免捕获)。 For example 例如

x [x := t]                       ===> t
x+3 [x := t]                     ===> t+3
f x + (\x -> x + 32) x [x := t]  ===> f t + (\x -> x + 32) t
[ f x y | y <- [1..x] ] [x := t] ===> [ f t y | y <- [1..t] ]

Again, this is not a Haskell operator, but a "mathematical" meta-level operator which takes as input Haskell code (syntax) and produces as output Haskell code (syntax). 同样,这不是Haskell运算符,而是“数学”元级别的运算符,该运算符将Haskell代码(语法)作为输入,并生成Haskell代码(语法)作为输出。

It is usually exploited to define beta reduction on lambdas: 通常利用它来定义lambda的beta减少:

(\x -> e) t ---beta---> e [x := t]

Anyway, in the posted expression 无论如何,在发布的表达式中

[ e | q ] [ v := f ] ++ [ e | v <- fs, q ]

the first [...] and the last are Haskell list comprehensions, while [v := f] is the meta-notation for substitution. [...]最后是Haskell的列表内涵,而[v := f]是元的符号,用于替换。 For instance, here's a fully evaluated example 例如,这是一个经过全面评估的示例

[ f x y | x <- 1:2:[] , y <- [0..x] ]
===> definition of list comprehension
[ f x y | y <- [0..x] ] [x := 1] ++ [ f x y | x <- 2:[] , y <- [0..x] ]
===> substitution
[ f 1 y | y <- [0..1] ] ++ [ f x y | x <- 2:[] , y <- [0..x] ]
===> definition of list comprehension
[ f 1 y | y <- [0..1] ] 
      ++ [ f x y | y <- [0..x] ] [x := 2] 
      ++ [ f x y | x <- [] , y <- [0..x] ]
===> substitution
[ f 1 y | y <- [0..1] ] ++ [ f 2 y | y <- [0..2] ] ++ [ f x y | x <- [] , y <- [0..x] ]
===> definition of list comprehension
[ f 1 y | y <- [0..1] ] ++ [ f 2 y | y <- [0..2] ] ++ []
===> many other steps here
[ f 1 0, f 1 1 ] ++ [ f 2 0, f 2 1, f 2 2 ] ++ []
===> concatenation
[ f 1 0, f 1 1, f 2 0, f 2 1, f 2 2 ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM