on master help sign in
Fix circular dependencies
commitc08dff75e585a293dae6ef459cb9326555c9b349 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateSat 21 Jan 2012, 10:59 (15 years ago) parent6a5d1fc
4 files changed+27−31
lib/prelude/list.idr+23 lib/prelude/maybe.idr+2−30 lib/prelude/monad.idr+1 src/Core/CaseTree.hs+1−1
lib/prelude/list.idr+23
@@ -110,3 +110,26 @@ split p xs = case break p xs of
110110 (chunk, []) => [chunk]
111111 (chunk, (c :: rest)) => chunk :: split p rest
112112
113+--------------------------------------------------------------------------------
114+-- Conversions
115+--------------------------------------------------------------------------------
116+
117+maybeToList : Maybe a -> List a
118+maybeToList Nothing = []
119+maybeToList (Just j) = [j]
120+
121+listToMaybe : List a -> Maybe a
122+listToMaybe [] = Nothing
123+listToMaybe (x::xs) = Just x
124+
125+--------------------------------------------------------------------------------
126+-- Misc
127+--------------------------------------------------------------------------------
128+
129+catMaybes : List (Maybe a) -> List a
130+catMaybes [] = []
131+catMaybes (x::xs) =
132+ case x of
133+ Nothing => catMaybes xs
134+ Just j => j :: catMaybes xs
135+
lib/prelude/maybe.idr+2−30
@@ -1,12 +1,10 @@
11module prelude.maybe
22
33import builtins
4−import prelude.list
5−import prelude.monad
64
75data Maybe a
8− = Nothing
9− | Just a
6+ = Nothing
7+ | Just a
108
119--------------------------------------------------------------------------------
1210-- Syntactic tests
@@ -20,18 +18,6 @@ isJust : Maybe a -> Bool
2018isJust Nothing = False
2119isJust (Just j) = True
2220
23−--------------------------------------------------------------------------------
24−-- Conversions
25−--------------------------------------------------------------------------------
26−
27−maybeToList : Maybe a -> List a
28−maybeToList Nothing = []
29−maybeToList (Just j) = [j]
30−
31−listToMaybe : List a -> Maybe a
32−listToMaybe [] = Nothing
33−listToMaybe (x::xs) = Just x
34−
3521--------------------------------------------------------------------------------
3622-- Misc
3723--------------------------------------------------------------------------------
@@ -48,20 +34,6 @@ toMaybe : Bool -> a -> Maybe a
4834toMaybe True j = Just j
4935toMaybe False j = Nothing
5036
51−catMaybes : List (Maybe a) -> List a
52−catMaybes [] = []
53−catMaybes (x::xs) =
54− case x of
55− Nothing => catMaybes xs
56− Just j => j :: catMaybes xs
57−
58−mapMaybe : (a -> Maybe b) -> List a -> List b
59−mapMaybe f [] = []
60−mapMaybe f (x::xs) =
61− case f x of
62− Nothing => mapMaybe f xs
63− Just j => j :: mapMaybe f xs
64−
6537--------------------------------------------------------------------------------
6638-- Class instances
6739--------------------------------------------------------------------------------
lib/prelude/monad.idr+1
@@ -3,6 +3,7 @@ module prelude.monad
33-- Monads and Functors
44
55import builtins
6+import prelude.list
67
78%access public
89
src/Core/CaseTree.hs+1−1
@@ -6,7 +6,7 @@ import Core.TT
66import Control.Monad.State
77import Debug.Trace
88
9−data CaseDef = CaseDef [Name] SC
9+data CaseDef = CaseDef [Name] SC [Term]
1010 deriving Show
1111
1212data SC = Case Name [CaseAlt]