たとえば、すべての呼び出しで haskell のリストまたは何かを出力するにはどうすればよいですか。
funct a list = funct (a + 1) (a : list)
print list here ??????? but how ?
たとえば、すべての呼び出しで haskell のリストまたは何かを出力するにはどうすればよいですか。
funct a list = funct (a + 1) (a : list)
print list here ??????? but how ?
デバッグのために、
import Debug.Trace
funct :: Integer -> [Integer] -> Bool
funct a list = trace (show list) $ funct (a + 1) (a : list)
どこでtrace :: String -> a -> a
。内部で使用unsafePerformIO
されるため、悪であり、デバッグ専用です。
遅延評価が原因で、デバッグ出力が驚くべき順序で表示され、プログラムが通常生成する出力とインターリーブされる場合があることに注意してください。
と
module TraceIt where
import Debug.Trace
funct :: Integer -> [Integer] -> Bool
funct 10 list = null list
funct a list = trace (show list) $ funct (a + 1) (a : list)
私は得る
*TraceIt> funct 1 []
[]
[1]
[2,1]
[3,2,1]
[4,3,2,1]
[5,4,3,2,1]
[6,5,4,3,2,1]
[7,6,5,4,3,2,1]
[8,7,6,5,4,3,2,1]
False
予想通り。
ダニエル・フィッシャーが提案したのと同じですが、unsafePerformIO
のみです。
> import System.IO.Unsafe
> let funct a list = unsafePerformIO $ do { print list; return $ funct (a + 1) (a : list) }
を使用するときに実際に何が起こっているかを説明する同様の質問を見てくださいunsafePerformIO
。