6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

print debug on Haskell

Last updated at Posted at 2013-09-09

Use unsafePerformIO

import System.IO.Unsafe

bmi weight height  = printDebug $ weight / (height / 100)^2

bmiTell :: Double -> Double -> String

bmiTell weight height
    | bmi weight height <= skinny = "skinny"
    | bmi weight height <= normal = "normal"
    | bmi weight height <= fat    = "fat"
    where skinny = 18.5
          normal = 25.0
          fat    = 30.0

printDebug x = unsafePerformIO $ do
    print $ "bmi: " ++ (show x)
    return x

main = print $ bmiTell 65.0 171.0

prints:

"bmi: 22.229061933586404"
"bmi: 22.229061933586404"
"normal"
6
6
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
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?