F# is a strongly-typed language that uses type inference. As a result, data types need not be explicitly declared by the programmer, rather will be deduced by the compiler during compilation. However, F# also allows explicit data type declaration. Being a .NET language, F# supports .NET types and objects. But it extends the type system and categorizes types as immutable types or mutable types. .NET objects classify as mutable types (which can be edited in-place), and are used to provide an object-oriented programming model. Immutable types (editing which creates a new instance without overwriting the older one) are primarily used for functional programming.
Like ML, F# includes a functional programming component supporting eager evaluation. For functional programming, it provides several constructs and a set of immutable types: tuples, records, discriminated unions and lists.[2] A tuple represents a collection of more than one values. It is represented as (A, B)
, where A and B can be of any type. A tuple can be used only to store values when the number of values is known at design-time and stays constant throughout execution. A record is a specialization of tuple where the data members are named, as in { Name: string; Age:int }
. Records can be created as { Name="AB"; Age=32 }
The with
keyword is used to create a copy of a record, as in { r with Name="CD" }
creates a new record that by changing the value of the Name
field in record r
(assuming the record created in the last example was named r
). The list type is a regular linked list represented either using a head::tail
notation (composition using the ::
- cons
- operator) or a shorthand as [item1; item2; item3]
. An empty list is defined as []
. A discriminated union (which is functionally like a type-safe version of C union) can be defined to hold a value of any of a pre-defined type.
F# | |
---|---|
Paradigm | multi-paradigm: imperative, functional, object-oriented |
Appeared in | 2005 (last revised 2008) |
Designed by | Microsoft Research |
Developer | Microsoft Research |
Latest release | 1.9.3(14)/ January 18, 2008 |
Typing discipline | static, strong, inferred |
Influenced by | Objective Caml, C# |
OS | Cross-platform (.NET Framework, Mono) |
License | Microsoft Research Shared Source license agreement ("MSR-SSLA") |
Website | F# at Microsoft Research |
No comments:
Post a Comment