Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cm/semant/version.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/semant/version.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)

1 : blume 632 (*
2 :     * Version numbering for CM libraries.
3 :     *
4 :     * (C) 2000 Lucent Technologies, Bell Laboratories
5 :     *
6 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
7 :     *)
8 :     signature VERSION = sig
9 :    
10 :     type t
11 :    
12 :     val fromString : string -> t option
13 :     val toString: t -> string
14 :     val compare : t * t -> order
15 :    
16 :     val nextMajor : t -> t
17 :    
18 :     val zero: t
19 :     end
20 :    
21 :     structure Version :> VERSION = struct
22 :    
23 :     type t = { major: int, minor: int list }
24 :    
25 :     fun fromString s =
26 :     let fun cvt (_, NONE) = NONE
27 :     | cvt (s, SOME l) =
28 :     (case Int.fromString s of
29 :     SOME i => SOME (i :: l)
30 :     | NONE => NONE)
31 :     in
32 :     case foldr cvt (SOME []) (String.fields (fn c => c = #".") s) of
33 :     SOME (maj :: min) => SOME { major = maj, minor = min }
34 :     | _ => NONE
35 :     end
36 :    
37 :     fun toString { major, minor } =
38 :     concat (Int.toString major ::
39 :     foldr (fn (i, l) => "." :: Int.toString i :: l)
40 :     [] minor)
41 :    
42 :     fun compare (v1: t, v2: t) = let
43 :     fun lcmp ([], []) = EQUAL
44 :     | lcmp ([], _) = LESS
45 :     | lcmp (_, []) = GREATER
46 :     | lcmp (h :: t, h' :: t') =
47 :     (case Int.compare (h, h') of
48 :     EQUAL => lcmp (t, t')
49 :     | unequal => unequal)
50 :     in
51 :     lcmp (#major v1 :: #minor v1, #major v2 :: #minor v2)
52 :     end
53 :    
54 :     fun nextMajor (v: t) = { major = #major v + 1, minor = [] }
55 :    
56 :     val zero = { major = 0, minor = [] }
57 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0