-
Notifications
You must be signed in to change notification settings - Fork 0
/
foobar.sml
32 lines (31 loc) · 1.39 KB
/
foobar.sml
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
exception Failure of string
structure EnviromentMap = RedBlackMapFn(struct
type ord_key = string
val compare = String.compare
end);
structure TheCgi = CGI(EnviromentMap)
structure ErrPages :> ERROR_PAGES = struct
fun errorPage (n,Failure(s)) () = print("Status: " ^ Int.toString n ^
"\nContent-type: text/plain\n\n" ^
s ^ " " ^ (Int.toString n))
| errorPage (n,e) () = print("Status: " ^ Int.toString n ^
"\nContent-type: text/plain\n\n" ^
(Int.toString n))
end
structure Baz :> APPLICATION = struct
structure EnvMap = EnviromentMap
structure ErrorPages = ErrPages
structure Cgi = TheCgi
fun fib (SOME n) = if n > 2 then fib(SOME(n-1))+fib(SOME(n-2)) else n
| fib (NONE) = raise Failure("Ilegal Fib")
fun foo [x] = SOME(fn () => print("Content-type: text/plain\n\n" ^ x))
| foo [] = SOME(fn () => print("Content-type: text/plain\n\n" ^ "foo"))
| foo ["fib",n] = SOME(fn () => print("Content-type: text/plain\n\n" ^
Int.toString(fib(Int.fromString n))))
| foo _ = NONE
fun bar [x,y] = SOME(fn () => print("Content-type: text/plain\n\n" ^x^y))
| bar _ = NONE
val dispatch = foo o' bar
end
structure TheApp = App(Baz)
val _ = TheApp.dispatch()