[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:22:15 EDT 2008
On Thu, 23 Oct 2008 15:07:09 +0900, Benjamin L.Russell
<DekuDekuplex at Yahoo.com> wrote:
>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 entree sidedish
> | entree == "pork" =
> | sidedish == "garlic bread" = ("pork", "garlic bread",
>"Merlot")
> | sidedish == "mozzarella sticks" = ("pork", "mozzarella
>sticks", "Merlot")
> | sidedish == "caviar" = ("pork", "caviar", "Sauvignon Blanc")
> | entree == "chicken" =
> | sidedish == "garlic bread" = ("chicken", "garlic bread",
>"Merlot")
> | sidedish == "mozzarella sticks" = ("chicken", "mozzarella
>sticks", "Sauvignon Blanc")
> | sidedish == "caviar"= ("chicken", "caviar", "Merlot")
> | entree == "tuna" =
> | sidedish == "garlic bread" = ("tuna", "garlic bread",
>"Sauvignon Blanc")
> | sidedish == "mozzarella sticks" = ("tuna", "mozzarella
>sticks", "Merlot")
> | sidedish == "caviar"= ("tuna", "caviar", "Merlot")
Sorry, I forgot to take care of list comprehension. I'm not quite
sure how to extract elements of both lists at the same time in a
nested guard. 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")
-- Benjamin L. Russell
More information about the Beginners
mailing list