1 implementation module StdMaybe
3 // ********************************************************************************
4 // Clean StdLib library module, version 1.0
5 // ********************************************************************************
7 from StdFunc import :: St;
8 from StdOverloaded import class ==(..);
14 isJust :: !(Maybe .x) -> Bool
15 isJust Nothing = False
18 isNothing :: !(Maybe .x) -> Bool
19 isNothing Nothing = True
22 u_isJust :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
23 u_isJust nothing=:Nothing
28 u_isNothing :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
29 u_isNothing nothing=:Nothing
34 fromJust :: !(Maybe .x) -> .x
37 accMaybe :: .(St .x .a) !u:(Maybe .x) -> (!Maybe .a,!u:Maybe .x)
44 mapMaybe :: .(.x -> .y) !(Maybe .x) -> Maybe .y
45 mapMaybe f (Just x) = Just (f x)
46 mapMaybe _ nothing = Nothing
48 instance == (Maybe x) | == x where
49 (==) Nothing maybe = case maybe of
52 (==) (Just a) maybe = case maybe of
56 maybeToList :: !(Maybe .a) -> [.a];
57 maybeToList Nothing = []
58 maybeToList (Just a) = [a]
60 listToMaybe :: ![.a] -> .Maybe .a;
61 listToMaybe [] = Nothing
62 listToMaybe [a:_] = Just a
64 catMaybes :: ![Maybe .a] -> .[.a];
65 catMaybes ms = [ m \\ Just m <- ms ]