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.

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

Tagged with: , ,
Posted in FSharp
2 comments on “FSharp for beginners : Finding Square of Range of Numbers in F#

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.

  • after 2 sixes of Sami .. I say LOL -> Virat KOHLI ... happy to see Kohli the ILL ATTITUDE MAN LOOSING .. 5 hours ago
  • It does not matter from where are you coming ? only does matter where are you going ? #djsays 5 hours ago
  • With people who participated in WCF day .. Great hosting by @CsharpCorner amd great leadership of @mcbkruse http://t.co/HkHjCdveJC 6 hours ago
  • RT @petekrueger: I've been using @Icenium. I would definitely recommend checking it out if you're tackling cross-platform mobile: http://t.… 6 hours ago
  • मुझे ग़म है की मैंने जिंदगी में कुछ नहीं पाया , ये ग़म दिल से निकल जाये अगर तुम मिलने आ जाओ 8 hours ago
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 2013
Follow

Get every new post delivered to your Inbox.

Join 2,123 other followers

%d bloggers like this: