1(*
2    Title:      Standard Basis Library: SML90 Signature and Structure
3    Author:     David Matthews
4    Copyright   David Matthews 1999, 2016
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
20(* This is intended for backwards compatibility only.  It should probably be withdrawn. *)
21
22signature SML90 =
23sig
24    exception Abs
25    exception Quot
26    exception Prod
27    exception Neg
28    exception Sum
29    exception Diff
30    exception Floor
31    exception Exp
32    exception Sqrt
33    exception Ln
34    exception Ord
35    exception Mod
36    exception Io of string
37    exception Interrupt
38    val sqrt : real -> real
39    val exp : real -> real
40    val ln : real -> real
41    val sin : real -> real
42    val cos : real -> real
43    val arctan : real -> real
44    val ord : string -> int
45    val chr : int -> string
46    val explode : string -> string list
47    val implode : string list -> string
48    type instream
49    type outstream
50    val std_in  : instream
51    val std_out : outstream
52    val open_in : string -> instream
53    val input : instream * int -> string
54    val lookahead : instream -> string
55    val close_in : instream -> unit
56    val end_of_stream : instream -> bool
57    val open_out : string -> outstream
58    val output : outstream * string -> unit
59    val close_out : outstream -> unit
60    end;
61
62structure SML90 :> SML90 =
63struct
64    exception Abs = Overflow and Quot = Overflow and Prod = Overflow
65          and Neg = Overflow and Sum = Overflow and Diff = Overflow
66          and Floor = Overflow and Exp = Overflow and Sqrt = Overflow
67          and Ln = Overflow and Ord = Overflow and Mod = Div
68          and Interrupt = RunCall.Interrupt
69
70    exception Io of string
71
72    fun sqrt x = if x < 0.0 then raise Sqrt else Real.Math.sqrt x
73
74    fun exp x = let val r = Real.Math.exp x in if Real.isFinite r then r else raise Exp end
75
76    fun ln x = if x < 0.0 then raise Ln else Real.Math.ln x
77
78    val sin = Real.Math.sin and cos = Real.Math.cos and arctan = Real.Math.atan
79
80    fun ord "" = raise Ord | ord s = Char.ord(String.sub(s, 0))
81
82    fun chr i = str(Char.chr i)
83    fun explode s = map String.str (String.explode s) 
84    val implode = String.concat
85
86    type instream = TextIO.instream and outstream = TextIO.outstream
87    val std_in  : instream = TextIO.stdIn and std_out : outstream = TextIO.stdOut
88
89    fun open_in s = TextIO.openIn s handle IO.Io _ => raise Io "Cannot open"
90    and open_out s = TextIO.openOut s handle IO.Io _ => raise Io "Cannot open"
91
92    fun input(str, i) = TextIO.inputN(str, i) handle IO.Io _ => raise Io "Cannot read"
93
94    fun lookahead strm =
95        case TextIO.lookahead strm of
96            NONE => ""
97        |   SOME ch => str ch
98
99    val close_in : instream -> unit = TextIO.closeIn
100    and close_out : outstream -> unit = TextIO.closeOut
101
102    fun output(str, s) = TextIO.output(str, s) handle IO.Io _ => raise Io "Cannot output"
103
104    val end_of_stream = TextIO.endOfStream
105end;
106