LoginSignup
6
1

More than 1 year has passed since last update.

Haskellでデバッグログを出す

Last updated at Posted at 2021-12-12

Haskell実行時にprintデバッグしたかったのだけど、使い方がわからなかったのでメモ

サンプルコード

import Debug.Trace

...

-- trace :: String -> a -> a 
-- traceはStringと何か(a)を受け取って(a)を返す

-- この後 name が評価されないとデバッグログが出ない。
name = trace ("name: -> " ++ show foo) ( foo )

-- List形式の場合は以下のように書けばデバッグログが出せるしわかりやすい(Python的?)。
[trace ("comprehending " ++ show x) (x + 1) | x <- [1..10]]

-- 使い方としてはwhereで
...
where
  xs = [trace ("comprehending " ++ show x) (x + 1) | x <- [1..10]]

-- とかやるといい感じにデバッグできる

あんまり内容がない。お粗末様でした。

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1