File: General.sml

package info (click to toggle)
polyml 5.6-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,892 kB
  • ctags: 34,453
  • sloc: cpp: 44,983; ansic: 24,520; asm: 14,850; sh: 11,730; makefile: 551; exp: 484; python: 253; awk: 91; sed: 9
file content (97 lines) | stat: -rw-r--r-- 3,430 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(*
    Title:      Standard Basis Library: General Structure
    Author:     David Matthews
    Copyright   David Matthews 1999

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*)

(* G&R 2004 status: checked, no change. *)

signature GENERAL =
  sig
    eqtype  unit
    type  exn
    exception Bind
    exception Chr
    exception Div
    exception Domain
    exception Fail of string
    exception Match
    exception Overflow
    exception Size
    exception Span
    exception Subscript
    val exnName : exn -> string
    val exnMessage : exn -> string
    datatype order = LESS | EQUAL | GREATER
    val ! : 'a ref -> 'a
    val := : ('a ref * 'a) -> unit
    val o : (('b -> 'c) * ('a -> 'b)) -> 'a -> 'c
    val before : ('a * unit) -> 'a
    val ignore : 'a -> unit
  end;


(* We declare the values in the top-level environment and construct
   the structure afterwards rather than opening the structure.  The
   reason for this is that we would prefer that types unit and exn
   did not capture the General structure name. *)
local
    open RuntimeCalls (* for POLY_SYS and EXC numbers *)
    val System_loadw: exn*int->string  = RunCall.run_call2 POLY_SYS_load_word
in
    exception Bind      = RunCall.Bind
    and       Div       = RunCall.Div
    and       Match     = RunCall.Match
    and       Overflow  = RunCall.Overflow
    and       Subscript = RunCall.Subscript
    and       Size      = RunCall.Size

    exception Domain and Span and Chr

    (* Exception packets.  The first word is the code, a unique id; the second is
       the exception name and the third is the exception argument. *)
    fun exnName (ex: exn) = System_loadw(ex, 1)
    
    (* Since exception packets carry a printer function this is just PolyML.makestring. *)
    fun exnMessage (ex: exn) = PolyML.makestring ex
    
    datatype order = LESS | EQUAL | GREATER
    
    fun op before (a, _ : unit) = a
    fun ignore _ = ()
    
    structure General (*: GENERAL *) (* Don't use a signature here. *) =
        struct
        type unit = unit (* This has to be primitive because its value is given by () *)
        type exn = exn
        exception Bind = Bind and Div = Div and Match = Match and Chr = Chr
        exception Overflow = Overflow and Domain= Domain and Fail = Fail
        exception Span = Span and Subscript = Subscript and Size = Size

        val exnName = exnName
        and op := = op := and ! = ! and op o = op o
        and op before = op before and ignore = ignore

        val exnMessage = exnMessage
        
        datatype order = datatype order
    end
end

(* Although these are available unqualified we always use them
   qualified within this library so that dependencies are
   maintained. *)