FSharp

FSharp for beginners : Finding Square of Range of Numbers in F#

This post is targeting audience starting with F Sharp. Level: 100

We can fine square of range of numbers in F# using List.Map

If you have range of numbers from 1 to 10 declared as below,

clip_image001

And a function to calculate square as below,

clip_image002

List.Map takes two parameters. It takes a mapping and the list.

clip_image004

If you print squreNumbers you should get as output square of numbers from 1 to 10.

clip_image006

Full code is as below,

</p>
<p>let number = [1..10]<br />
let squre x= x*x<br />
let squreNumbers = List.map squre number<br />
printfn &quot;SqureNubers = %A&quot; squreNumbers<br />
open System<br />
printfn &quot;Press any key to continue&quot;<br />
Console.ReadKey(true);</p>
<p>

Press F5 to get the output,

clip_image002

I hope this post was useful. Thanks for reading  Smile

If you find my posts useful you may like to follow me on twitter http://twitter.com/debug_mode or may like Facebook page of my blog http://www.facebook.com/DebugMode.Net If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

About Dhananjay Kumar

Dhananjay Kumar is Developer, Blogger , Speaker, Learner , Mindcracker & Microsoft MVP.

Discussion

Trackbacks/Pingbacks

  1. Pingback: Dew Drop – September 26, 2011 | Alvin Ashcraft's Morning Dew - September 26, 2011

  2. Pingback: Monthly Report September 2011: Total Posts 28 « debug mode…… - October 1, 2011

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 )

Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,380 other followers

Tweets

Categories

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my current or previous employer's view in anyway. © Copyright 2012