All pastes #384099 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-06 20:37 UTC
rendered paste body
(* Pizza datatype*)
datatype topping = Onion of real | Green_Peppers of real | Mushrooms of real | Goat_Cheese of real | Pepperoni of               real | Eggplant of real;
(*types of pizza, single topping, 2 topping....etc*)
datatype pizza = single of topping
        | double of topping*topping
        | triple of topping*topping*topping
        | plain of real;
(*returns the price of the single item*)
fun getPrice(Onion(x)) = x
        |getPrice(Green_Peppers(x)) = x
        |getPrice(Mushrooms(x)) = x
        |getPrice(Goat_Cheese(x))=x
        |getPrice(Pepperoni(x))=x
        |getPrice(Eggplant(x))=x;

(*price a single type of pizza assumes if they order a topping, then the cheese price is included in the order*);
fun pizza_price(single(x))=getPrice(x)
        | pizza_price(double(x,y))=getPrice(x)+getPrice(y)
        | pizza_price(triple(x,y,z))=getPrice(x)+getPrice(y)+getPrice(z)
        | pizza_price(plain(x))=x;

(*allows for unlimited toppings*)
datatype pizza2 = topList of topping list | plain of real;
fun pizza2_helper(x::xs)=getPrice(x)+pizza2_helper(xs);	
fun pizza2_price(x)=pizza2_helper(tl(tl(x)));