
On Thu, 23 Oct 2008 18:39:52 +0900, Benjamin L. Russell
instance Show Wine where show (Red Merlot) = "Merlot" show (Red Syrah) = "Syrah" show (Red Port) = "Port" show (White SauvignonBlanc) = "Sauvignon Blanc" show (White Riesling) = "Riesling" show (White PinotNoir) = "Pinot Noir"
instance Show Red where show Merlot = "Merlot" show Syrah = "Syrah" show Port = "Port"
instance Show White where show SauvignonBlanc = "Sauvignon Blanc" show Riesling = "Riesling" show PinotNoir = "Pinot Noir"
The only remaining issue is whether there is a way to define the type constructor for Wine without pre-defining parts that are later defined in the type constructors for Red and White. In the above code, for example,
instance Show Wine where show (Red Merlot) = "Merlot"
essentially pre-defines the following definition later given in the type constructor for Red:
instance Show Red where show Merlot = "Merlot"
This seems redundant. Since the type definition for Wine is data Wine = Red Red | White White the type constructors for Red and White both require an argument, so show (Red Merlot) = ... seems reasonable. This would seem to imply that if I need to reduce redundancy, I should probably rewrite the RHS of the above line. Is there a way to refer to the type constructors for Red and White in the type constructor for Wine? -- Benjamin L. Russell