Is it possible to print all abbreviations in Haskell - using WinHugs?

I wrote the following function and executed using WinHugs

teneven = [x | x <- [1..10], even x] 

My conclusion:

 Main> teneven [2,4,6,8,10] :: [Integer] (63 reductions, 102 cells) 

is there anyway to print all abbreviations .. so that I can find out that the main evaluation is happening inside WinHugs?

+6
haskell lazy-evaluation evaluation
source share
3 answers

Some ideas:

  • The debug command line parameter (which you can set with :set +d in Hugs) is informative, but very verbose and does not show any abbreviations in Haskell syntax.

  • Try Hat - Haskell Tracer . I just tried this with a simple program, and it's pretty cool. However, I am not on Windows, and I do not know how difficult it would be to run it. This is probably quite complicated, which is a shame, as it is cool and, in fact, what you want. If you run it, you can get something like this information from Hat:

     main = {IO} teneven = [2,4,6,8,10] _foldr (\..) [1,2,3,4,5,6,7,8, ...] [] = [2,4,6,8,10] (\..) 1 [2,4,6,8,10] = [2,4,6,8,10] (\..) 2 [4,6,8,10] = [2,4,6,8,10] (\..) 3 [4,6,8,10] = [4,6,8,10] (\..) 4 [6,8,10] = [4,6,8,10] (\..) 5 [6,8,10] = [6,8,10] (\..) 6 [8,10] = [6,8,10] (\..) 7 [8,10] = [8,10] (\..) 8 [10] = [8,10] (\..) 9 [10] = [10] (\..) 10 [] = [10] 

    There is even lambda. In addition, if you want, Hat can track foldr calls and other internal calls; by default it does not.

+5
source share

Here you have some examples of using Debug.Trace and Hugs.Observe.

 import Debug.Trace fact :: Integer -> Integer fact 0 = trace "fact 0 ->> 1" 1 fact n = trace ("fact " ++ show n) (n * fact (n-1)) import Hugs.Observe fact :: Integer -> Integer fact 0 = observe "fact 0" 1 fact n = observe "fact n" (n * fact (n-1)) 

Hope this helps you figure out how to print all shortcuts with WinHungs.

+5
source share

Believe me, you do not want to go this route.

The set (and order) of abbreviations used in each particular case will depend on the specific implementation of the language (hugs can do this in one way, ghci in another way, jhc in another, etc.).

It is better to read something about common ways to implement a compiler / interpreter / virtual machine for a functional language - for example, SECD machines, etc.

A few links:

+2
source share

All Articles