[英]Haskell TransformListComp extension
I read this guide about haskell language extensions and was somewhat confused by the TransformListComp explanation. 我阅读了有关haskell语言扩展的指南 ,并且对TransformListComp解释感到有些困惑。 I tried to rewrite all the TransformListComp expression without the sugar but I'm not sure if I'm correct.
我尝试重写所有没有糖的TransformListComp表达式,但我不确定我是否正确。
Also I think there is a mistake in the guide: The example for "then group using clauses" is impossible as "(groupBy (==))" is not of the right type ("Eq a" can't be used) 另外我认为指南中有一个错误:“then group using clauses”的例子是不可能的,因为“(groupBy(==))”不是正确的类型(“Eq a”不能使用)
[foo | x1 <- xs1,
x2 <- xs2,
...
xi <- xsi,
then f,
xj <- xsj,
...
xn <- xni
]
==
[foo | f x1 <- xs1,
f x2 <- xs2,
...
f xi <- xsi,
xj <- xsj,
...
xn <- xni
]
-------------------
[foo | x1 <- xs1,
x2 <- xs2,
...
xi <- xsi,
then f by exp,
xj <- xsj,
...
xn <- xni
]
==
f (\(x1,x2,...,xi) -> exp) [(x1,x2,...,xi) |
x1 <- xs1,
x2 <- xs2,
...
xi <- xsi]
>>=(\(x1,x2,...,xi) ->
[foo |
xj <- xsj,
...
xn <- xni
])
-------------------
[foo | x1 <- xs1,
x2 <- xs2,
...
xi <- xsi,
then group using f,
xj <- xsj,
...
xn <- xni
]
==
map unzipI (f [(x1,x2,...,xi) |
x1 <- xs1,
x2 <- xs2,
...
xi <- xsi])
>>=(\(xs1,xs2,...,xsi) ->
[foo |
x1 <- xs1,
x2 <- xs2,
...
xi <- xsi,
xj <- xsj,
...
xn <- xni
])
unzipI :: [(t1,t2,...tn)] -> ([t1],[t2]..,[tn])
-------------------
[foo | x1 <- xs1,
x2 <- xs2,
...
xi <- xsi,
then group by exp using f,
xj <- xsj,
...
xn <- xni
]
==
map unzipI (f (\(x1,x2,...,xi) -> exp) [(x1,x2,...,xi) |
x1 <- xs1,
x2 <- xs2,
...
xi <- xsi])
>>=(\(xs1,xs2,...,xsi) ->
[foo |
x1 <- xs1,
x2 <- xs2,
...
xi <- xsi,
xj <- xsj,
...
xn <- xni
])
unzipI :: [(t1,t2,...tn)] -> ([t1],[t2]..,[tn])
You could rewrite 你可以改写
[ foo | x1 <- xs1
, x2 <- xs2
, then f
, x3 <- xs3 ]
more correctly as 更正确的是
[ foo | (x1, x2) <- f [ (x1, x2) | x1 <- xs1
, x2 <- xs2 ]
, x3 <- xs3 ]
The groupBy
mistake seems to have been fixed in the meantime, the article's example works. 在此期间,该
groupBy
错误似乎已得到解决,该文章的示例有效。
Another useful source on this extension is in this blog post , also see the original article comprehensive comprehensions . 这个扩展的另一个有用的来源是在这篇博文中 ,也看到了原始文章的综合理解 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.