Haskell: Alternative, non-circular definition of Redex?

江枫思渺然 提交于 2019-12-10 22:35:59

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/27593644/haskell-alternative-non-circular-definition-of-redex

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