Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/system/Basis/Implementation/option.sml
ViewVC logotype

Annotation of /sml/trunk/src/system/Basis/Implementation/option.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 416 - (view) (download)

1 : monnier 416 (* option.sml
2 :     *
3 :     * COPYRIGHT (c) 1997 AT&T Labs Research.
4 :     *)
5 :    
6 :     structure Option : OPTION =
7 :     struct
8 :     open Assembly (* for type 'a option *)
9 :    
10 :     exception Option
11 :    
12 :     fun getOpt (SOME x, y) = x
13 :     | getOpt (NONE, y) = y
14 :     fun isSome (SOME _) = true
15 :     | isSome NONE = false
16 :     fun valOf (SOME x) = x
17 :     | valOf _ = raise Option
18 :    
19 :     fun filter pred x = if (pred x) then SOME x else NONE
20 :     fun join (SOME opt) = opt
21 :     | join NONE = NONE
22 :     fun map f (SOME x) = SOME(f x)
23 :     | map f NONE = NONE
24 :     fun mapPartial f (SOME x) = f x
25 :     | mapPartial f NONE = NONE
26 :     fun compose (f, g) x = map f (g x)
27 :     fun composePartial (f, g) x = mapPartial f (g x)
28 :    
29 :     end;
30 :    
31 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0