Haskell 模板:zipn
我正在阅读 模板 Haskell 教程 来自 archive.org,因为它从 haskell.org 丢失,并注意到它已损坏,就好像随机部分已被取出。
我希望了解他们对 zipn 的实现。他们唯一的代码是:
\ y1 y2 y3 >
case (y1,y2,y3) of
(x1:xs1,x2:xs2,x3:xs3) > (x1,x2,x3) : ff xs1 xs2 xs3
(_,_,_) > []
mkZip :: Int > Expr > Expr
mkZip n name = lam pYs (caseE (tup eYs) [m1,m2])
where
(pXs, eXs) = genPE "x" n
(pYs, eYs) = genPE "y" n
(pXSs,eXSs) = genPE "xs" n
pcons x xs = [p| $x : $xs |]
b = [| $(tup eXs) : $(apps(name : eXSs)) |]
m1 = simpleM (ptup (zipWith pcons pXs pXSs)) b
m2 = simpleM (ptup (copies n pwild)) (con "[]")
这对我来说毫无意义。有人有教程的好副本吗?或者 archive.org 上的内容就是这样吗?
I was reading a Template Haskell tutorial from archive.org since it was lost from haskell.org, and noticed that it is corrupted, as if random parts had been taken out.
I was hoping to read about their implementation of zipn. The only code they have there is:
\ y1 y2 y3 >
case (y1,y2,y3) of
(x1:xs1,x2:xs2,x3:xs3) > (x1,x2,x3) : ff xs1 xs2 xs3
(_,_,_) > []
mkZip :: Int > Expr > Expr
mkZip n name = lam pYs (caseE (tup eYs) [m1,m2])
where
(pXs, eXs) = genPE "x" n
(pYs, eYs) = genPE "y" n
(pXSs,eXSs) = genPE "xs" n
pcons x xs = [p| $x : $xs |]
b = [| $(tup eXs) : $(apps(name : eXSs)) |]
m1 = simpleM (ptup (zipWith pcons pXs pXSs)) b
m2 = simpleM (ptup (copies n pwild)) (con "[]")
This makes no sense to me. Does anyone have a good copy of the tutorial? Or is what's on archive.org what it is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速搜索产生了这篇题为“Haskell 模板元编程" 由 Simon Peyton-Jones 亲自编写!
希望这会有所帮助!
A quick search produced this paper entitled "Template Meta-programming for Haskell" written by Simon Peyton-Jones himself!
Hope this helps!
请注意,据我所知,本文中发现的 zipN 实现实际上从未使用 GHC 的发布版本进行编译。我尝试自己编译它,并收到此电子邮件中描述的错误:
http://www.haskell.org/pipermail/template-haskell/2003-July/000126.html(未实现模式切片)。
这在 2003 年没有实现,但今天仍然没有实现: http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/template-haskell.html(不支持模式切片)
但是您可以在那里找到 zipWithN 的实现使用模板haskell:
http://www.haskell.org/haskellwiki/Template_Haskell#zipWithN
Note that as far as I can tell the implementation of zipN as found in this paper never in fact compiled with a published version of GHC. I attempted to compile it myself, and I got the error described in this email:
http://www.haskell.org/pipermail/template-haskell/2003-July/000126.html (pattern slices are not implemented).
That was not implemented in 2003, but it's still not implemented today: http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/template-haskell.html (pattern slices are not supported)
However there you can find an implementation of zipWithN using template haskell:
http://www.haskell.org/haskellwiki/Template_Haskell#zipWithN