76 people like it.

Struct Tuple

Two/Three/Four-element generic tuples implemented as a value types for writing more efficient F# code.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
type Tup<'a, 'b> =
  struct 
    val mutable Item1 : 'a
    val mutable Item2 : 'b
    
    new(item1, item2) = { 
      Item1 = item1
      Item2 = item2
    }
  end

let stup a b = Tup(a, b)

stup 1 2
Tup.Item1: 'a
Tup.Item2: 'b
val item1 : 'a
val item2 : 'b
val stup : a:'a -> b:'b -> Tup<'a,'b>

Full name: Script.stup
val a : 'a
val b : 'b
Multiple items
type Tup<'a,'b> =
  struct
    new : item1:'a * item2:'b -> Tup<'a,'b>
    val mutable Item1: 'a
    val mutable Item2: 'b
  end

Full name: Script.Tup<_,_>

--------------------
Tup()
new : item1:'a * item2:'b -> Tup<'a,'b>
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/2P
Posted:13 years ago
Author:fholm
Tags: struct , tuple