A couple of questions left

Now, I have some time to write about a couple of questions I have received about F#, and their answers.

1. To get a specific element of a tuple :

If we do not want to create variables for the elements that we are not interested in of a tuple, we can use “_” for all other elements, i.e.:

let drinks= (Coke, 0.45, “Coca Cola Zero”)
let _, _, valBrand= drinks

which is interpreted into the compiler as we see in the FS Interactive window:

val drinks : string * float * string = (“Coke”, 0.45, “Coca Cola Zero”)
val valBrand : string = “Coca Cola Zero”

2. “namespace” keywords stays as is, and we can have either a module or a type [i.e. C# class] under a namespace. The example would be :
File1: Drink.fs

namespace Vesta.Beverage
module Drink=
let drinks= (Coke, 0.45, “Coca Cola Zero”)
let _, _, valBrand= drinks

File2: BeverageCalculator.fs [placed under the Drink.fs if they are in the same project.]

namespace Vesta.Calculator
open Vesta.Beverage.Drink
module BeverageCalculator=
let drink= valBrand

So, we can use everything from the first namespace,
Happy F# days!

Advertisements

One thought on “A couple of questions left

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s