1(*
2    Title:      Standard Basis Library: General Structure
3    Author:     David Matthews
4    Copyright   David Matthews 1999, 2016-17
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License version 2.1 as published by the Free Software Foundation.
9    
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14    
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18*)
19
20signature GENERAL =
21  sig
22    eqtype  unit
23    type  exn
24    exception Bind
25    exception Chr
26    exception Div
27    exception Domain
28    exception Fail of string
29    exception Match
30    exception Overflow
31    exception Size
32    exception Span
33    exception Subscript
34    val exnName : exn -> string
35    val exnMessage : exn -> string
36    datatype order = LESS | EQUAL | GREATER
37    val ! : 'a ref -> 'a
38    val := : ('a ref * 'a) -> unit
39    val o : (('b -> 'c) * ('a -> 'b)) -> 'a -> 'c
40    val before : ('a * unit) -> 'a
41    val ignore : 'a -> unit
42  end;
43
44
45(* We declare the values in the top-level environment and construct
46   the structure afterwards rather than opening the structure.  The
47   reason for this is that we would prefer that types unit and exn
48   did not capture the General structure name. *)
49local
50in
51    exception Bind      = RunCall.Bind
52    and       Div       = RunCall.Div
53    and       Match     = RunCall.Match
54    and       Overflow  = RunCall.Overflow
55    and       Subscript = RunCall.Subscript
56    and       Size      = RunCall.Size
57
58    exception Domain and Span and Chr
59
60    (* Exception packets.  The first word is the code, a unique id; the second is
61       the exception name and the third is the exception argument. *)
62    fun exnName (ex: exn): string = RunCall.loadWordFromImmutable(ex, 0w1)
63    
64    (* Since exception packets carry a printer function this is just PolyML.makestring. *)
65    fun exnMessage (ex: exn) = PolyML.makestring ex
66    
67    datatype order = LESS | EQUAL | GREATER
68    
69    fun op before (a, _ : unit) = a
70    fun ignore _ = ()
71    
72    structure General (*: GENERAL *) (* Don't use a signature here. *) =
73        struct
74        type unit = unit (* This has to be primitive because its value is given by () *)
75        type exn = exn
76        exception Bind = Bind and Div = Div and Match = Match and Chr = Chr
77        exception Overflow = Overflow and Domain= Domain and Fail = Fail
78        exception Span = Span and Subscript = Subscript and Size = Size
79
80        val exnName = exnName
81        and op := = op := and ! = ! and op o = op o
82        and op before = op before and ignore = ignore
83
84        val exnMessage = exnMessage
85        
86        datatype order = datatype order
87    end
88end
89
90(* Although these are available unqualified we always use them
91   qualified within this library so that dependencies are
92   maintained. *)
93