Question about Reductions.
Hello: I am a student of computer science and a user of Hugs, I am interested to know How hugs calculate the number of reductions when evaluating an expression. I dont understand for example why evaluating the expression 9 gives 12 reductions. Main> 9 9 (12 reductions, 18 cells) Main> I would appreciate if someone can help me with my question ------------------------------------------------- This mail sent through IMP: http://horde.org/imp/
G'day. On Thu, Feb 06, 2003 at 11:12:37AM -0500, e2041800@luna.escuelaing.edu.co wrote:
I am a student of computer science and a user of Hugs, I am interested to know How hugs calculate the number of reductions when evaluating an expression. I dont understand for example why evaluating the expression 9 gives 12 reductions.
Internally, Hugs is actually evaluating an expression more like this (simplified for clarity): hugsIORun (putStr (show 9)) The show function (from the Show typeclass) turns the value into a String so it can be printed. The hugsIORun and putStr combination are to print the result. Most of the reductions will be from converting the Int into its String represenation. First, it is converted into an Integer, then it's converted into a String, which requires a bit of arithmetic and heap allocation (since a String is actually a list of Chars). Then, of course, because the list is constructed lazily, the putStr function has to evaluate the string one element at a time in order to print it, with probably two reductions per character in the String (one to evaluate the (:) and the other to evaluate the Char). Cheers, Andrew Bromage
participants (2)
-
Andrew J Bromage -
e2041800@luna.escuelaing.edu.co