summaryrefslogtreecommitdiff
path: root/tests/examplefiles/example.sml
blob: 31db47d2f8a9beec5f066e11fcbb46a90ec5c9ed (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
structure C = struct
   val a = 12
   fun f x = x + 5
end

(*(*(*(*(* This file is all pretty strange Standard ML *)*)*)*) (**)*)
(* Robert J. Simmons *)

(* Comments (* can be nested *) *)
structure S = struct
  val x = (1, 2, "three")
end

structure Sv = struct
  (* These look good *)
  val x = (1, 2, "three")
  val z = #2 x

  (* Although these look bad (not all the numbers are constants),       *
   * they never occur in practice, as they are equivalent to the above. *)
  val x = {1 = 1, 3 = "three", 2 = 2}
  val z = #
            2 x

  val || = 12
end

signature S = sig end

structure S = struct
  val x = (1, 2, "three")
  datatype 'a t = T of 'a
       and u = U of v * v
  withtype v = {left: int t, right: int t}
  exception E1 of int and E2
  fun 'a id (x: 'a) : 'a = x

  val 
      'a id = fn (x : 'a) => x
end

signature R = sig
  type t
  val x : t
  val f : t * int -> int
end
structure R : R = struct
  datatype t = T of int
  val x : t = T 0
  fun f (T x, i : int) : int = x + i
  fun 'a id (x: 'a) : 'a = x
end

signature BA_Z = sig 
   val s: int
   include S R
end 

structure b______ = struct (* What (* A * strange * name *) for ) a ( struct *)

val !%&$#+-/:<=>?@\~`^|* = 3

type struct' = int list
and 'a sig' = 'a list
and ('a, 'b) end' = 'b option * 'a list

structure baz = struct
  structure Bar = struct 
    val foo = !%&$#+-/:<=>?@\~`^|*
  end  
end

infixr +!+ 
fun (a +!+ b) = (op +) (a, b)

open baz S R

val$$$ = fn x => fn y => fn z => fn w => w
val (foo, ++, bar, ||) = (4, baz.Bar.foo, !%&$#+-/:<=>?@\~`^|*, Bar.foo)
val _ = $$$foo++bar||

val val'ue : ' list = []
val struct3 : (' -> ') = fn x => x
val end_struct_' : ('a -> 'a) = fn x => x
val x : (''a -> ''a) = fn x => x
val x : ('''' -> '''') = fn x => x
val x : unit = print "Weird, huh?\n"
val w = {x=1,y=2,##= =3,4=3}
val {##=, x, 4=a,...} = w
val z = #4 w
val z = # ##= w

fun f x y 0 = 4 
  | f x y z = 4 + Sv.||

exception Foo of int
datatype ('0, 'b, '_, ') f'o'o = Bar | baZ12' | dsfa_fad | #@$ | Bug
and (', ''', '''', ''''') bar = 
   Bee of unit
 | Ben of (', ''', '''', ''''') f'o'o * int
 | X of ''' list

fun q x = raise Foo x
and h x = raise Foo (~x)

val x = 4
and y = 5

fun q 0 = 4
  | q 1 = (case 1 of 1 => 2 | 3 => 4 | x => y)
  | q y = case y of 1 => 2 | 3 => 4 | x => y

val x = ref true
fun q 0 = 4
  | q 1 = if false then case 1 of 1 => 2 | 3 => 4 | x => y else 19
  | q 2 = (while !x handle Match => !x | Fail _ => !x do () ; 2)
  | q x = (raise Match) handle Domain => 9 | Match => 3

fun p 0 = 12
  | p 1 = 8
  | p 2 = r false
  | p x = r true
and r true = 19
  | r false = 12

val _ = 123
val _ = 0001
val _ = ~123
val _ = ~0001
val _ = 0w12412
val _ = 0w12412
val _ = 0xfA0
val _ = ~0xfA0
val _ = 0wxfA0
val _ = 1.4
val _ = ~1.4
val _ = 1e~2
val _ = 1E~2
val _ = 1e2
val _ = 1E2
val _ = 1.4e~2
val _ = 1.4E~2
val _ = 1.4e2
val _ = 1.4E2

val c = #"\000"
val st = "foo \
 	 \ bar" ^ "baz \        
  	 \ and \ 
   	 \ such\n"

val () = print st

val _ = foo::bar::4::[++]

end