[Haskell-beginners] Re: how to define a user datatype consisting of instances of String?

Benjamin L.Russell DekuDekuplex at Yahoo.com
Thu Oct 23 02:27:34 EDT 2008


On Thu, 23 Oct 2008 15:22:17 +0900, Benjamin L. Russell
<DekuDekuplex at Yahoo.com> wrote:

>Here's a slight revision; would this work?
>	
>module Wine where 
>    
>data Wine = Red | White
>data Red = "Merlot"
>data White = "Sauvignon Blanc"
>data Entree = "pork" | "chicken" | "tuna"
>data SideDish = "garlic bread" | "mozzarella sticks" | "caviar"
>
>wine :: [Entree] -> [SideDish] -> [(Entree, SideDish, Wine)]
>wine entrees sidedishes
>    | entree <- entrees == "pork" = 
>        | sidedish <- sidedieshes == "garlic bread" = ("pork", "garlic
>bread",
>"Merlot")
>        | sidedish <- sidedishes == "mozzarella sticks" = ("pork",
>"mozzarella
>sticks", "Merlot")
>        | sidedish <- sidedishes == "caviar" = ("pork", "caviar",
>"Sauvignon Blanc")
>    | entree <- entrees == "chicken" = 
>        | sidedish <- sidedieshes == "garlic bread" = ("chicken",
>"garlic bread",
>"Merlot")
>        | sidedish <- sidedieshes == "mozzarella sticks" = ("chicken",
>"mozzarella
>sticks", "Sauvignon Blanc")
>        | sidedish <- sidedieshes == "caviar"= ("chicken", "caviar",
>"Merlot")
>    | entree <- entrees == "tuna" = 
>        | sidedish <- sidedieshes == "garlic bread" = ("tuna", "garlic
>bread",
>"Sauvignon Blanc")
>        | sidedish <- sidedieshes == "mozzarella sticks" = ("tuna",
>"mozzarella
>sticks", "Merlot")
>        | sidedish <- sidedieshes == "caviar"= ("tuna", "caviar",
>"Merlot")

Sorry; my earlier revision contained some typos where "sidedishes" was
misspelled as "sidedieshes."  Here is a corrected version:
	
module Wine where 
    
data Wine = Red | White
data Red = "Merlot"
data White = "Sauvignon Blanc"
data Entree = "pork" | "chicken" | "tuna"
data SideDish = "garlic bread" | "mozzarella sticks" | "caviar"

wine :: [Entree] -> [SideDish] -> [(Entree, SideDish, Wine)]
wine entrees sidedishes
    | entree <- entrees == "pork" = 
        | sidedish <- sidedishes == "garlic bread" = ("pork", "garlic
bread",
"Merlot")
        | sidedish <- sidedishes == "mozzarella sticks" = ("pork",
"mozzarella
sticks", "Merlot")
        | sidedish <- sidedishes == "caviar" = ("pork", "caviar",
"Sauvignon Blanc")
    | entree <- entrees == "chicken" = 
        | sidedish <- sidedishes == "garlic bread" = ("chicken",
"garlic bread",
"Merlot")
        | sidedish <- sidedishes == "mozzarella sticks" = ("chicken",
"mozzarella
sticks", "Sauvignon Blanc")
        | sidedish <- sidedishes == "caviar"= ("chicken", "caviar",
"Merlot")
    | entree <- entrees == "tuna" = 
        | sidedish <- sidedishes == "garlic bread" = ("tuna", "garlic
bread",
"Sauvignon Blanc")
        | sidedish <- sidedishes == "mozzarella sticks" = ("tuna",
"mozzarella
sticks", "Merlot")
        | sidedish <- sidedishes == "caviar"= ("tuna", "caviar",
"Merlot")

-- Benjamin L. Russell



More information about the Beginners mailing list