Click here to Skip to main content
Licence CPOL
First Posted 2 Dec 2011
Views 4,923
Bookmarked 0 times

F# Core Types

By | 2 Dec 2011 | Technical Blog
F# Core Types
A Technical Blog article. View original blog here.[^]

Besides the primitive types, the F# library includes several core types that will allow you to organize, manipulate and process data.

Unit

The unit type is a value signifying nothing of consequence. unit can be thought of as a concrete representation of void and is represented in code via ():

> let x=();;
val x : unit=()
> x;;
val it : unit()

if expres­sions without a matching else must return unit because if they did return a value, what would happen if else was hit?

Also, in F#, every function must return a value, think method in C# and the void return type, so even if the function doesn’t conceptually return any­thing, then it should return a unit value.

The ignore function can swallow a function’s return value if you want to return unit:

> let square x=x*x;;
val square :int->int
> ignore (square 3);;
val it : unit=()

Tuple

A tuple (pronounced two-pull) is an ordered collection of data,easy way to group common pieces of data together. For example, tuples can be used to track the intermediate results of a computation.

To create an instance of a tuple, separate group of values with comma, and optionally place them within parentheses. Let's have fullName as an instance of a tuple, while string * string is the tuples type:

> let fullName = ("ganesan", "senthilvel");;
val fullName : string * string = ("ganesan", "senthilvel")

Tuples can contain any number of values of any type. You can have a tuple that contains other tuples.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

GanesanSenthilvel

Architect

India India

Member

Currently working as IT Architect for Financial Services applications. Out of 16+ years, spent six career years at major IT firms in USA. Basically from C, C++, VC++, C# family. Loves driving, spending time with friends&family, building my farm house.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 2 Dec 2011
Article Copyright 2011 by GanesanSenthilvel
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid