As an example, say I wish to implement a function which sums up a list of Num
s. Halfway through coding it, I wish to debug it with Debug.Trace
:
module T where
import Debug.Trace
dosum :: (Num a) => [a] -> a
dosum xs = dosum' 0 xs
where
dosum' n [] = n
dosum' n (x:xs) = trace (show n) $ dosum' (n+x) xs
The problem is that this will not compile:
Could not deduce (Show a) arising from a use of dosum'
from the context (Num a)
I can add (Show a)
to dosum
and then remove it when I am finished debugging (in real life, I will want to have a type which is not necessarily in Show
, but I will debug with integers). This can get cumbersome if there are a few functions involved and I keep adding removing Show a
statements.
I want to have a function unsafeShow
unsafeShow :: a -> String
which works if a
is Show a
and is free to crash if it is not. Is this possible?