This project is read-only.
Using the Set type

Category:
Data Types
Description: Create a set of particular unicode characters using a Microsoft.FSharp.Collections.Set.
Code:
let SampleSet1() =
let data = "The quick brown fox jumps over the lazy dog"
let set =
data.ToCharArray()
|> Set.ofSeq
for c in set do
printfn "Char : '%c'" c


Execution Result:
Char : ' '
Char : 'T'
Char : 'a'
Char : 'b'
Char : 'c'
Char : 'd'
Char : 'e'
Char : 'f'
Char : 'g'
Char : 'h'
Char : 'i'
Char : 'j'
Char : 'k'
Char : 'l'
Char : 'm'
Char : 'n'
Char : 'o'
Char : 'p'
Char : 'q'
Char : 'r'
Char : 's'
Char : 't'
Char : 'u'
Char : 'v'
Char : 'w'
Char : 'x'
Char : 'y'
Char : 'z'

Using the Map type

Category:
Data Types
Description: Create a histogram of the occurrences of particular unicode characters using a Microsoft.FSharp.Collections.Map.
Code:
let SampleMap1() =
let data = "The quick brown fox jumps over the lazy dog"
let histogram =
data.ToCharArray()
|> Seq.groupBy (fun c -> c)
|> Map.ofSeq
|> Map.map (fun k v -> Seq.length v)
for (KeyValue(c,n)) in histogram do
printfn "Number of '%c' characters = %d" c n

Execution Result:
Number of ' ' characters = 8
Number of 'T' characters = 1
Number of 'a' characters = 1
Number of 'b' characters = 1
Number of 'c' characters = 1
Number of 'd' characters = 1
Number of 'e' characters = 3
Number of 'f' characters = 1
Number of 'g' characters = 1
Number of 'h' characters = 2
Number of 'i' characters = 1
Number of 'j' characters = 1
Number of 'k' characters = 1
Number of 'l' characters = 1
Number of 'm' characters = 1
Number of 'n' characters = 1
Number of 'o' characters = 4
Number of 'p' characters = 1
Number of 'q' characters = 1
Number of 'r' characters = 2
Number of 's' characters = 1
Number of 't' characters = 1
Number of 'u' characters = 2
Number of 'v' characters = 1
Number of 'w' characters = 1
Number of 'x' characters = 1
Number of 'y' characters = 1
Number of 'z' characters = 1

typeof operator

Category:
Data Types
Description: Demostrate how to use typeof operator.
Code:
let SampleTypeOf() = 
let intType = typeof
printfn "%s can be retrieved by using typeof" (intType.Name)

Execution Result:
Int32 can be retrieved by using typeof

typedefof operator

Category:
Data Types
Description: Demostrate how to use typedefof operator to create generic type.
Code:
let SampleTypeDefof() = 
let intType = typeof
let listType = typedefof>
let listIntType = listType.MakeGenericType(intType)
printfn "make a List type using typedefof operator."
printfn "the newly created type's full name is %s" (listIntType.FullName)

Execution Result:
make a List type using typedefof operator.
the newly created type's full name is System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

Last edited Sep 13, 2011 at 12:15 AM by ttliu2000, version 2

Comments

No comments yet.