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,
And a function to calculate square as below,
List.Map takes two parameters. It takes a mapping and the list.
If you print squreNumbers you should get as output square of numbers from 1 to 10.
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 "SqureNubers = %A" squreNumbers<br /> open System<br /> printfn "Press any key to continue"<br /> Console.ReadKey(true);</p> <p>
Press F5 to get the output,
I hope this post was useful. Thanks for reading
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.Follow @debug_mode