
On Sat, May 05, 2007 at 11:36:16AM +0700, Monang Setyawan wrote:
Hi, I'm a beginner Haskell user.
Is there any way to trace/debug the function application in GHC?
Absolutely! stefan@stefans:/tmp$ ghci X.hs ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.7.20070502, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. [1 of 1] Compiling Main ( X.hs, interpreted ) Ok, modules loaded: Main. *Main> :break fac Breakpoint 0 activated at X.hs:(2,0)-(5,34) *Main> fac 3 Stopped at X.hs:(2,0)-(5,34) _result :: Int [X.hs:(2,0)-(5,34)] *Main> :step Stopped at X.hs:2:8-15 _result :: Int x :: Int fac' :: Int -> Int -> Int [X.hs:2:8-15] *Main> x 3 [X.hs:2:8-15] *Main> :step Stopped at X.hs:(4,8)-(5,34) _result :: Int [X.hs:(4,8)-(5,34)] *Main> :list 3 where 4 [1mfac' 0 a = a 5 fac' k a = fac' (k-1) (a*k)[0m 6 [X.hs:(4,8)-(5,34)] *Main> :step Stopped at X.hs:5:19-34 _result :: Int a :: Int ds :: Int [X.hs:5:19-34] *Main> a 1 [X.hs:5:19-34] *Main> ds 3 [X.hs:5:19-34] *Main> :list 4 fac' 0 a = a 5 fac' k a = [1mfac' (k-1) (a*k)[0m 6 [X.hs:5:19-34] *Main> Leaving GHCi. stefan@stefans:/tmp$ cat X.hs fac :: Int -> Int fac x = fac' x 1 where fac' 0 a = a fac' k a = fac' (k-1) (a*k) stefan@stefans:/tmp$ Stefan