There is a bug in GHC: mkName ":" doesn't work right. let pcons x xs = return $ InfixP x (mkName ":") xs The reason is that ":" is built-in syntax, and I wasn't handing that right. You can get around it by replacing the call to mkName by a quoted name, thus: let pcons x xs = return $ InfixP x '(:) xs but I will fix the bug. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On | Behalf Of Ch. A. Herrmann | Sent: 29 November 2005 16:55 | To: template-haskell@haskell.org | Subject: [Template-haskell] TH problem | | Dear TH gurus, | | I'm desperately trying to convert the old TH examples to work with ghc-6.4.1 | and got stuck with a problem I cannot explain. Although the splice seems | to be correct, the compiler complains about the (:) in the gerated | pattern match. | I appended the source files. They are not very nice right now, because all | guidance I have are the types generated by haddock and all effort I spent | was to make them fit somehow. | Please tell me where the error is and how to proceed or, even | better, please send me the corrected source files back. | | Many thanks in advance. | | Christoph | ------------------------------------------------------------------------ ---------------- | Loading package base-1.0 ... linking ... done. | Compiling Zip ( ./Zip.hs, interpreted ) | Compiling Sel ( ./Sel.hs, interpreted ) | Compiling Main ( Main.hs, interpreted ) | Loading package haskell98-1.0 ... linking ... done. | Loading package haskell-src-1.0 ... linking ... done. | Loading package template-haskell-1.0 ... linking ... done. | Main.hs:16:18: | Main.hs:16:18-23: Splicing expression | zipN 3 | ======> | let | zp[a4fV] = \ y1 y2 y3 | -> case (y1, y2, y3) of | (x1 : xs1, x2 : xs2, x3 : xs3) | -> ((x1, x2, x3) `GHC.Base.:` (zp[a4fV] | xs1 xs2 xs3)) | (_, _, _) -> GHC.Base.[] | in zp[a4fV] | In the second argument of `($)', namely `$[splice](zipN 3) as bs cs' | In a 'do' expression: print $ ($[splice](zipN 3) as bs cs) | In the definition of `main': | main = do | let as = ['a' .. 'e'] | bs = map toUpper as | cs = map ord as | print $ ($[splice](zipN 3) as bs cs) | let ds = [1 .. ] | print $ ($[splice](zipN 4) ds as bs cs) | print $ ($[splice](sel 1 3) (2, 'a', 6)) | | Main.hs:16:18: Not in scope: data constructor `:' | | Main.hs:16:18: Not in scope: data constructor `:' | | Main.hs:16:18: Not in scope: data constructor `:' | Failed, modules loaded: Sel, Zip. | -- | Christoph | | | |
Hello Simon, Wednesday, November 30, 2005, 4:49:13 PM, you wrote: SPJ> let pcons x xs = return $ InfixP x '(:) xs is not let pcons x xs = [| x:xs |] better? -- Best regards, Bulat mailto:bulatz@HotPOP.com
Hi Bulat, the (:) is used as a pattern, not as an expression, but I'm not sure whether there is a similar notation for (:) patterns using quotation brackets. -- Christoph Bulat Ziganshin wrote:
Hello Simon,
Wednesday, November 30, 2005, 4:49:13 PM, you wrote:
SPJ> let pcons x xs = return $ InfixP x '(:) xs
is not
let pcons x xs = [| x:xs |]
better?
Hello Ch., Tuesday, December 06, 2005, 5:43:13 PM, you wrote: CAH> the (:) is used as a pattern, not as an expression, but I'm not sure whether CAH> there is a similar notation for (:) patterns using quotation brackets. sorry, i don't think :) [p| x:xs |] according to docs, but i don't test it. at least we can complain if it's not work :) -- Best regards, Bulat mailto:bulatz@HotPOP.com
Hi Bulat, it seems not to be implemented yet: *** Exception: typecheck/TcSplice.lhs:(128,0)-(150,44): Non-exhaustive patterns in function tc_bracket Personally, I'm happy with the auxiliary pcons function, but I'll have problems to suggest my TH-based programs to other people, I'm afraid. -- Christoph Bulat Ziganshin wrote:
Hello Ch.,
Tuesday, December 06, 2005, 5:43:13 PM, you wrote:
CAH> the (:) is used as a pattern, not as an expression, but I'm not sure whether CAH> there is a similar notation for (:) patterns using quotation brackets.
sorry, i don't think :)
[p| x:xs |] according to docs, but i don't test it. at least we can complain if it's not work :)
participants (3)
-
Bulat Ziganshin -
Ch. A. Herrmann -
Simon Peyton-Jones