Haskell:Redex的替代性非圆形定义吗? [英] Haskell: Alternative, non-circular definition of Redex?

查看:75
本文介绍了Haskell:Redex的替代性非圆形定义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Haskell中的redex是什么,什么不是什么,我感到很困惑,因此我花了一些时间,但是我想反馈一下我是否正确.

我发现了redex的定义,它是循环的; Etymology : From "reducible expression" Definition: Redex (plural redexes): (mathematics) Something to be reduced according to the rules of a formal system. http://en.wiktionary.org/wiki/redex

以上定义假定人们知道如何减少.所以对我来说,这就像在说蓝色是蓝色的品质"一样,也是圆形的.

然后,我找到了一篇博客文章,该文章对redex的定义如下: Any subgraph that matches a rule is called a reducible expression, or redex for short. https://hackhands.com/lazy-evaluation-works-haskell/

这要好得多,但是从字面上看,这意味着它是特定于实现的,这似乎很奇怪.换句话说,如果我可以用两种不同的方式使用不同的评估树来定义myfunc,那么什么是redex的定义将有所不同.我认为那不是真的.

似乎重要的是评估分析树,以及反过来是什么是原语的定义.我找不到Haskell基元的定义,但发现了一个可能不完整的列表:重要的Haskell基元函数"

谢谢!

编辑;我相信这是我尝试提供的一些示例. 第一个是来自Haskell编程的Graham Hutton. -- Consider these cases; -- 1.An expression using a function mult ::(Int, Int)-> Int -- pg.126 mult (x,y) = x*y mult(1+2, 3+4) -- This has 3 redexes, one for each argument and one for the call, per the book

-- 2.Now consider using '*', a primitive, instead of mul, a function, 7 + (6*8) -- This has one redex, only the 6*8, per discussions.

-- 3.Finally, contrast to all primitives without any parentheses to indicate a new evaluation level 1 + 2*3 -- This should have zero redexes, I believe, since they are only primitive expressions which can be evaluated all at once.

解决方案

功能语言中的redex,一旦您通过语法(即将1 + 2从infix转换为(+) 1 2),看起来就是像f x一样-即一个函数和一个参数,使得该函数尚未应用于该参数.

一个人不必担心哪些东西是原始"函数,而不是这些东西

事实上,相反,休顿,我想说1+2具有两个 redex,因为它实际上是未固化的,所以已减负"形式为((+) 1) 2.

I got quite confused about what is and is not a redex in Haskell, so I spent some time on it, but I would like feedback whether I got it right.

I found this definition of a redex, and it is circular; Etymology : From "reducible expression" Definition: Redex (plural redexes): (mathematics) Something to be reduced according to the rules of a formal system. http://en.wiktionary.org/wiki/redex

The above definition presumes one knows how to reduce. So to me this is like saying "Bluish is the quality of looking blue", which is also circular.

Then I found a blog post that defines redex as follows; Any subgraph that matches a rule is called a reducible expression, or redex for short. https://hackhands.com/lazy-evaluation-works-haskell/

That's much better but, taken literally it means that it is implementation specific, which seems odd. In other words, if I can define myfunc in two different ways with different evaluation trees, the definition of what is a redex would differ. I don't think that is true.

It seems that the important thing is the evaluation parse tree and, in turn, the definition of what is a primitive. I could not find a definition of Haskell primitives, but I found a possibly incomplete list: "Important Haskell primitive functions" http://www.cs.sjsu.edu/faculty/smithj/oldclass/152f11/haskell-primitives.html

Is there a real definition of Haskell primitives that I have missed?

Moving on, the list helps identify some examples of primitives and non-primitives. -- Primitive: *, / , div -- Not-Primitive (not on the list): mul

Putting this all together, it says that a primitive function evaluation is reducible, being a leaf node on the evaluation tree. The reduction reduces from a function call to a data point.

Thus, how is this definition ? Redex: In Haskell, evaluation proceeds with the base case that any primitive function application constitutes a leaf node of the evaluation tree. Such leaves are reducible from function applications into pure data elements. Thus we define all leaf nodes as reducible expressions, or "redexs" for short.

thank you!

Edit; Here are some examples I'm trying to accommodate, that I believe true. The first is from Graham Hutton , Programming in Haskell. -- Consider these cases; -- 1.An expression using a function mult ::(Int, Int)-> Int -- pg.126 mult (x,y) = x*y mult(1+2, 3+4) -- This has 3 redexes, one for each argument and one for the call, per the book

-- 2.Now consider using '*', a primitive, instead of mul, a function, 7 + (6*8) -- This has one redex, only the 6*8, per discussions.

-- 3.Finally, contrast to all primitives without any parentheses to indicate a new evaluation level 1 + 2*3 -- This should have zero redexes, I believe, since they are only primitive expressions which can be evaluated all at once.

解决方案

A redex in a functional language, once you get past the syntax (i.e. translating 1 + 2 from infix into (+) 1 2) is just anything that looks like f x -- i.e. a function and an argument such that the function has not been applied to the argument.

One shouldn't worry about which things are and aren't "primitive" functions

And in fact, contra-Hutton, I'd say that 1+2 has two redexes, since it is actually uncurried, and so the "desugared" form is ((+) 1) 2.

这篇关于Haskell:Redex的替代性非圆形定义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆