Changes between Version 50 and Version 51 of ExplicitCallStack


Ignore:
Timestamp:
Jan 30, 2007 5:31:17 PM (8 years ago)
Author:
guest
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExplicitCallStack

    v50 v51  
    302302 
    303303   e :: [Int] -> Int 
    304    e = f 10 
    305  
    306    f :: Int -> [Int] -> Int 
    307    f = \x -> case fac x < 10 of 
    308                 True  -> \_ -> 3 
    309                 False -> hd 
    310  
    311    hd :: [a] -> a 
    312    hd = \x -> case x of 
    313                  [] -> error "hd: empty list" 
    314                  (x:_) -> x 
    315  
    316    fac :: Int -> Int 
    317    fac = \n -> case n == 0 of 
    318                   True -> 1 
    319                   False -> n * fac (n - 1) 
    320 }}} 
    321  
     304   e = f ["e"] 10 
     305 
     306   f :: Trace -> Int -> [Int] -> Int 
     307   f = \t x -> case fac ("f":t) x < 10 of 
     308                  True  -> \_ -> 3 
     309                  False -> hd ("f":t) 
     310 
     311   hd :: Trace -> [a] -> a 
     312   hd = \t x -> case x of 
     313                   [] -> error ("hd: empty list " ++ show t)      {- simple hack so we can see the stack -} 
     314                   (x:_) -> x 
     315 
     316   fac :: Trace -> Int -> Int                              
     317   fac = \t n -> case n == 0 of 
     318                    True -> 1 
     319                    False -> n * fac ("fac":t) (n - 1)            {- no stack pruning, though there ought to be -} 
     320}}} 
     321 
     322When you fun this program you get: 
     323{{{ 
     324   Program error: hd: empty list ["f","e"] 
     325}}} 
     326Which is essentially: 
     327{{{ 
     328   e -> f -> hd 
     329}}} 
     330''Note'': this is different to the stack trace given by hat-stack above. 
    322331 
    323332A problem with this transformation style is that it is sensitive to the position of lambdas in the body of a declaration. For example, it transforms these two functions differently, even though they are semantically equivalent: