Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- open System
- type sandwichRec = | Ham | Salami | Cheese
- type saladRec = | Caesar | Waldorf | Mixed
- type cakeRec = | Carrot | Vanilla | Chocolate
- type Food = | Sandwich of sandwichRec | Salad of saladRec | Cake of cakeRec
- type Size = | Small | Medium | Large
- type ShoppingBag = {food: Food; size: Size}
- let aUser: ShoppingBag = {food = Sandwich (sandwichRec.Ham); size = Size.Large}
- let getPriceForBag shoppingBag =
- let priceForFood =
- match shoppingBag.food with
- | Sandwich (sandRec) ->
- match sandRec with
- | Ham -> 10
- | Salami -> 15
- | Cheese -> 25
- | Salad (saldRec) ->
- match saldRec with
- | Caesar -> 10
- | Waldorf -> 15
- | Mixed -> 25
- | Cake (cakeRec) ->
- match cakeRec with
- | Carrot -> 5
- | Vanilla -> 15
- | Chocolate -> 30
- let sizePrice =
- match shoppingBag.size with
- | Small -> 5
- | Medium -> 10
- | Large -> 25
- (sizePrice + priceForFood)
- type CanteenMessage =
- |OrderFood of ShoppingBag * int
- |LeaveAComment of string
- let userExample: CanteenMessage = OrderFood(aUser, 4)
- let canteenFoodAgent =
- MailboxProcessor.Start (fun inbox ->
- let rec processFood state =
- async {
- let! msg = inbox.Receive ()
- match msg with
- | OrderFood (bag, qty)->
- printfn "Please pay %i DKK for your %i portions" (getPriceForBag (bag) * qty) qty
- | LeaveAComment (comm) ->
- match comm with
- | "delicious" -> printfn "The food was amazing!!"
- | "satisfied" -> printfn "The food was good..!"
- | _ -> printfn "unsatisfied (%s)" comm
- return! processFood msg
- }
- processFood (LeaveAComment("initial")))
- [<EntryPoint>]
- let main argv =
- printfn "Hello World from F#!"
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement