[Template-haskell] RE: Template Haskell...

Simon Peyton-Jones simonpj at microsoft.com
Fri Oct 31 14:55:47 EST 2003


| stringType :: String -> Q [Dec]
| stringType s = [|
| 	newtype $s = $s String
| 	show$s :: $s -> ShowS
| 	show$s ($s x) = showString x
| 	instance Show $s where
| 		showsPrec _ x = show$s x
| 	instance Eq $s where
| 		($s x) ($s y) = (x==y)
| 	|]

Yes, that's part of what we had in mind (see Section 5 of
http://research.microsoft.com/~simonpj/tmp/notes.ps).  You'd have to
say:

 stringType :: String -> Q [Dec]
 stringType s = [|
 	newtype $tc_var = $con_var String
 	$show_var :: $tc_var -> ShowS
 	$show_var ($con_var x) = showString x
 	instance Show $tc_var where
 		showsPrec _ x = $show_var x
	instance Eq $tc_var where
		($con_var x) ($con_var y) = (x==y)
	|]
    where
	tc_var = mkVar s
	con_var = mkVar s
	show_var = mkVar ("show" ++ s)





More information about the template-haskell mailing list