0 people like it.

Unit List

 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: 
29: 
30: 
31: 
32: 
33: 
34: 
type [<Measure>] b
 
type Vec<'a, [<Measure>] 'n> = 
    | V of List<'a>
 
let nil<'a> : Vec<'a, 1> =
    V([])
 
let cons (x : 'a) (V(xs) : Vec<'a,'n>) : Vec<'a,'n b> =
    V(x :: xs)
 
let append (V(xs) : Vec<'a,'n>) (V(ys) : Vec<'a,'m>) : Vec<'a,'n 'm> =
    V(xs @ ys)
 
let zip (V(xs) : Vec<'a,'n>) (V(ys) : Vec<'b,'n>) : Vec<'a * 'b,'n> =
    V(List.zip xs ys)
 
let sum (V(xs) : Vec<int,'n>) : int = 
    List.sum xs
 
let l = cons 1 (cons 2 (cons 3 nil))
let g = zip l l

(*
error FS0001: Type mismatch. Expecting a
    Vec<int,1>    
but given a
    Vec<int,b ^ 3>    
The unit of measure '1' does not match the unit of measure 'b ^ 3' 
*)
//let h = zip l (append l l)
 
printfn "%A" l
printfn "%A" g
Multiple items
type MeasureAttribute =
  inherit Attribute
  new : unit -> MeasureAttribute

Full name: Microsoft.FSharp.Core.MeasureAttribute

--------------------
new : unit -> MeasureAttribute
[<Measure>]
type b

Full name: Script.b
type Vec<'a,'n> = | V of List<'a>

Full name: Script.Vec<_,_>
union case Vec.V: List<'a> -> Vec<'a,'n>
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val nil<'a> : Vec<'a,1>

Full name: Script.nil
val cons : x:'a -> Vec<'a,'n> -> Vec<'a,'n b>

Full name: Script.cons
val x : 'a
val xs : List<'a>
val append : Vec<'a,'n> -> Vec<'a,'m> -> Vec<'a,'m 'n>

Full name: Script.append
val ys : List<'a>
val zip : Vec<'a,'n> -> Vec<'b,'n> -> Vec<('a * 'b),'n>

Full name: Script.zip
val ys : List<'b>
val zip : list1:'T1 list -> list2:'T2 list -> ('T1 * 'T2) list

Full name: Microsoft.FSharp.Collections.List.zip
val sum : Vec<int,'n> -> int

Full name: Script.sum
val xs : List<int>
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val sum : list:'T list -> 'T (requires member ( + ) and member get_Zero)

Full name: Microsoft.FSharp.Collections.List.sum
val l : Vec<int,b ^ 3>

Full name: Script.l
val g : Vec<(int * int),b ^ 3>

Full name: Script.g
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view Test code New version

More information

Link:http://fssnip.net/3Q
Posted:15 years ago
Author:
Tags: