Haskell 模板:zipn

发布于 2024-11-03 01:47:17 字数 804 浏览 1 评论 0原文

我正在阅读 模板 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

全部不再 2024-11-10 01:47:17

快速搜索产生了这篇题为“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!

仅一夜美梦 2024-11-10 01:47:17

请注意,据我所知,本文中发现的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文