logo       

[ ghc-Bugs-1194808 ] Template panics the compiler: msg#00080

lang.haskell.glasgow.bugs

Subject: [ ghc-Bugs-1194808 ] Template panics the compiler

Bugs item #1194808, was opened at 2005-05-03 22:59
Message generated for change (Comment added) made by simonpj
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=1194808&group_id=8032

Category: Template Haskell
Group: 6.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Simon Peyton Jones (simonpj)
Summary: Template panics the compiler

Initial Comment:
Experimenting a little with the template example from
http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html
i tried to put a small parser into it, and ran into this:

ghc --make -fth template.hs -o template
Chasing modules from: template.hs
Skipping Printf ( ./Printf.hs, ./Printf.o )
Compiling Main ( template.hs, template.o )
Loading package base-1.0 ... linking ... done.
Loading package haskell98-1.0 ... linking ... done.
Loading package parsec-1.0 ... linking ... done.
Loading package template-haskell-1.0 ... linking ... done.
ghc: panic! (the `impossible' happened, GHC version 6.4):
./Printf.hs:(40,0)-(42,20): Non-exhaustive patterns in
function gen


Please report it as a compiler bug to
glasgow-haskell-bugs@xxxxxxxxxxx,
or http://sourceforge.net/projects/ghc/.


Compilation exited abnormally with code 1 at Wed May 04
00:50:37

I was running on winxp

The code was:

--template.hs:
module Main where
import Printf (pr)

main = putStrLn ( $(pr "hello"))

--Printf.hs:

module Printf where

-- Skeletal printf from the paper.
-- It needs to be in a separate module to the one where
-- you intend to use it.

-- Import some Template Haskell syntax
import Language.Haskell.TH
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Char
import Text.ParserCombinators.Parsec.Prim
import Text.ParserCombinators.Parsec.Combinator


-- Describe a format string
data Format = D | S | L String

parsePercent = do char '%'
k <- oneOf "sd"
return (case k of
's' -> S
'd' -> D)
parseString = do s <- many (satisfy (/= '%'))
return (L s)

-- Is not used yet since it doesn't work

-- parseFormat' = return many (parsePercent <|>
parseString)

-- Parse a format string. This is left largely to you
-- as we are here interested in building our first ever
-- Template Haskell program and not in building printf.
parseFormat :: String -> [Format]
parseFormat s = case (parse (many parsePercent) [] s) of
Left err -> fail "Printf parser
error"
Right x -> x

-- Generate Haskell source code from a parsed
representation
-- of the format string. This code will be spliced into
-- the module which calls "pr", at compile time.
gen :: [Format] -> ExpQ
gen [D] = [| \n -> show n |]
gen [S] = [| \s -> s |]
gen [L s] = stringE s

-- Here we generate the Haskell code for the splice
-- from an input format string.
pr :: String -> ExpQ
pr s = gen (parseFormat s)



----------------------------------------------------------------------

>Comment By: Simon Peyton Jones (simonpj)
Date: 2005-05-19 08:00

Message:
Logged In: YES
user_id=50165

Wolfgang is right: the bug is in your code, but GHC's error
report was bad.

It's now much improved. The fix will be in 6.4.1


----------------------------------------------------------------------

Comment By: Wolfgang Thaller (wthaller)
Date: 2005-05-04 00:19

Message:
Logged In: YES
user_id=566359

This is actually a failure in your Printf module - function gen was called
with something that is not a one-element list.
There is a GHC bug here, though: GHC shouldn't report a pattern-match
failure in user-defined code as a compiler bug.


----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=1194808&group_id=8032


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise