为什么foldl1'没有推广到可折叠?

时间:2016-09-06 06:03:57

标签: haskell typeclass fold

标题说明了一切。 foldl1foldl'都推广到Foldable,而foldl1'则不是。foldl1' :: (a -> a -> a) -> [a] -> a 。这只是最近的疏忽吗?或者它是一种设计选择?

foldl1'的类型是

foldl1

我希望它与foldl1 :: Foldable t => (a -> a -> a) -> t a -> a 具有相同的类型:

foldl1'

我还看到// https://mvnrepository.com/artifact/joda-time/joda-time libraryDependencies += "joda-time" % "joda-time" % "2.9.4" // https://mvnrepository.com/artifact/org.joda/joda-convert libraryDependencies += "org.joda" % "joda-convert" % "1.8.1" 导出import org.joda.time.Duration import org.joda.time.format.DateTimeFormat val funcTimeDiffernceInSeconds = (startTime: String, endTime: String) => { //println("starttime is "+startTime+"\nendtime "+endTime) if (startTime.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}[\\s]{1}[\\d]{2}:[\\d]{2}:[\\d]{2}:[\\d]+") && endTime.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}[\\s]{1}[\\d]{2}:[\\d]{2}:[\\d]{2}:[\\d]+")) { //val start = new JDateTime(startTime, "yyyy-MM-dd HH:mm:ss:SSS") val formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss:SSS") val start = formatter.parseDateTime(startTime) val end = formatter.parseDateTime(endTime) new Duration(start, end).getStandardSeconds.toString } else "Invalid" } Data.List导出funcTimeDiffernceInSeconds("2016-02-21 00:17:43:126", "2016-02-22 00:17:43:126") res0: String = 86400 。也许这是相关的?

1 个答案:

答案 0 :(得分:0)

也许广义形式只是would have no good place to live?这背后可能还有一些性能原因,但我无法找到有关它的任何信息。