1

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?

Muchin
  • 4,887
  • 4
  • 23
  • 25
  • 1
    Maybe use one of the other tutorials? http://stackoverflow.com/questions/5724413/is-there-any-template-haskell-tutorial-for-someone-who-doesnt-know-lisp/5724957#5724957 – Don Stewart Apr 22 '11 at 17:04
  • See the [Template Haskell page on HaskellWiki](http://www.haskell.org/haskellwiki/Template_Haskell#zipWithN). – hammar Aug 27 '11 at 03:01
  • I don't see anything wrong with the link. Maybe you're just _thinking_ it's corrupted because... it's Haskell – Mu Mind Feb 04 '12 at 05:47

2 Answers2

1

A quick search produced this paper entitled "Template Meta-programming for Haskell" written by Simon Peyton-Jones himself!

Hope this helps!

Ed Holloway-George
  • 5,092
  • 2
  • 37
  • 66
  • 4
    OK, first of all that link is broken, and second of all if you looked at the tutorial Muchin was using, the first sentence says the tutorial was written because the paper was too confusing. If you're looking for the paper, though, it's here: http://research.microsoft.com/en-us/um/people/simonpj/papers/meta-haskell/ – Jeff Burka Apr 22 '11 at 23:38
0

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

Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81