本文介绍了为什么“traceId”返回消息字符串本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这很奇怪,返回消息字符串本身。为什么有人想这样做?



有一个常见的情况是, traceId 会派上用场吗? p>

解决方案

编辑:



向David提醒,David提醒了我的 traceId'正好是 traceShowId 。 p>

因此, traecId 只是 String - > String 单态版本的多态 traceShowId ::显示 - > a - >



旧答案



解释 traceId 的一种方法是它是一个 String 专门版本的更多一般 traceId'不在stdlib中:

  traceId':: Show a => a  - > a 
traceId'x = trace(show x)x

所以

  traceId = traceId':: String  - > String 

示例:

  my = id; func = id; chain = id; value = 3 

main = do
print $ length $ traceIdchain is called!
print $ length $ traceId'[1,2,3]

但由于某种原因 traceId 的一般版本,我称之为 traceId',不在stdlib中。


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?

解决方案

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.

这篇关于为什么“traceId”返回消息字符串本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 16:06