Functional languages use different names for stuff you already know. This page summarizes this.
1:
|
|
This line defines an algebraic data type.
The type keyword introduces a type (named Vector<'a>
) and one single
constructor called VectorC
.
In class notation this looks like:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: |
|
Algebraic data types have no identity, i.e. the only way to compare them is by using their value. There is no built in way to modify values. Algebraic data types come in two favors: Product and Sum types.
1: 2: 3: 4: |
|
Maybe<'a>
is a sum type. In F# we call it discriminated union. Other
frequently used names are variant or tagged union.
MyTuple<'a,'b>
is a product type. The cross product of its
parts is the set of inhabited values. In F# product types are
special discriminated unions with only one single variant.
Please note that abstract data types are something completly different. Abstract data types describe abstract programming interfaces and (possibly) properties thereof.
As copy from wikipedia consider imperative abstract variables (simplest non-trivial abstract data type (ADT)): An abstract variable V is a mutable entity that admits two operations:
- store(V,x) where x is a value of unspecified nature; and
- fetch(V), that yields a value; with the constraint that
- fetch(V) always returns the value x used in the most recent store(V,x) operation on the same variable V.
| Nothing
| Just of 'a
Full name: Concepts-and-names.Maybe<_>
union case MyTuple.MyTuple: 'a * 'b -> MyTuple<'a,'b>
--------------------
type MyTuple<'a,'b> = | MyTuple of 'a * 'b
Full name: Concepts-and-names.MyTuple<_,_>