问题
I found it really weird that traceId returns the message string itself. Why would anyone want to do that?
Is there a common scenario where traceId
would come in handy?
回答1:
EDIT:
Credits to David who drew attention on the fact that my traceId'
is exactly traceShowId
.
Hence, traecId
is simply the String -> String
monomorphic version of the polymorphic traceShowId :: Show a -> a -> a
, which also strips the printed string from quotes.
Old answer:
One way to interpret traceId
is that it's a String
-specialized version of a more general traceId'
which is not in the stdlib:
traceId' :: Show a => a -> a
traceId' x = trace (show x) x
so that
traceId = traceId' :: String -> String
Example:
my = id; func = id; chain = id; value = 3
main = do
print $ length $ traceId "chain is called!"
print $ length $ traceId' [1,2,3]
but for some reason the general version of traceId
, which I've called traceId'
, is not in the stdlib.
来源:https://stackoverflow.com/questions/33059378/why-does-traceid-return-the-message-string-itself