File tree Expand file tree Collapse file tree 8 files changed +56
-8
lines changed Expand file tree Collapse file tree 8 files changed +56
-8
lines changed Original file line number Diff line number Diff line change 1+ module Haskell.Data.Maybe where
2+
3+ open import Haskell.Prelude
4+
5+ isJust : Maybe a → Bool
6+ isJust Nothing = False
7+ isJust (Just _) = True
8+
9+ isNothing : Maybe a → Bool
10+ isNothing Nothing = True
11+ isNothing (Just _) = False
12+
13+ fromJust : (x : Maybe a) → @0 {IsJust x} → a
14+ fromJust Nothing = error "fromJust Nothing"
15+ fromJust (Just x) = x
16+
17+ fromMaybe : {a : Set } → a → Maybe a → a
18+ fromMaybe d Nothing = d
19+ fromMaybe _ (Just x) = x
20+
21+ listToMaybe : List a → Maybe a
22+ listToMaybe [] = Nothing
23+ listToMaybe (x ∷ _) = Just x
24+
25+ maybeToList : Maybe a → List a
26+ maybeToList Nothing = []
27+ maybeToList (Just x) = x ∷ []
28+
29+ mapMaybe : (a → Maybe b) → List a → List b
30+ mapMaybe f [] = []
31+ mapMaybe f (x ∷ xs) = maybe id _∷_ (f x) (mapMaybe f xs)
32+
33+ catMaybes : List (Maybe a) → List a
34+ catMaybes = mapMaybe id
Original file line number Diff line number Diff line change @@ -5,8 +5,10 @@ module Haskell.Extra.Delay where
55open import Agda.Builtin.Size public
66
77open import Haskell.Prelude
8- open import Haskell.Prim.Thunk
8+
9+ open import Haskell.Data.Maybe
910open import Haskell.Extra.Refinement
11+ open import Haskell.Prim.Thunk
1012
1113private variable
1214 x y z : a
Original file line number Diff line number Diff line change @@ -137,6 +137,3 @@ IsJust : Maybe a → Set
137137IsJust Nothing = ⊥
138138IsJust (Just _) = ⊤
139139
140- fromJust : (x : Maybe a) → @0 {IsJust x} → a
141- fromJust Nothing = error "fromJust Nothing"
142- fromJust (Just x) = x
Original file line number Diff line number Diff line change @@ -11,7 +11,3 @@ data Maybe {@0 ℓ} (a : Set ℓ) : Set ℓ where
1111maybe : ∀ {@0 ℓ₁ ℓ₂} {@0 a : Set ℓ₁} {@0 b : Set ℓ₂} → b → (a → b) → Maybe a → b
1212maybe n j Nothing = n
1313maybe n j (Just x) = j x
14-
15- fromMaybe : {a : Set } → a → Maybe a → a
16- fromMaybe d Nothing = d
17- fromMaybe _ (Just x) = x
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ import FunCon
9494import Issue308
9595import Issue324
9696import Assert
97+ import Issue377
9798
9899{-# FOREIGN AGDA2HS
99100import Issue14
@@ -185,4 +186,5 @@ import FunCon
185186import Issue308
186187import Issue324
187188import Assert
189+ import Issue377
188190#-}
Original file line number Diff line number Diff line change 1+ module Issue377 where
2+
3+ open import Haskell.Prelude
4+ open import Haskell.Data.Maybe
5+
6+ test : Integer
7+ test = fromMaybe 0 (Just 12 )
8+
9+ {-# COMPILE AGDA2HS test #-}
Original file line number Diff line number Diff line change @@ -89,4 +89,5 @@ import FunCon
8989import Issue308
9090import Issue324
9191import Assert
92+ import Issue377
9293
Original file line number Diff line number Diff line change 1+ module Issue377 where
2+
3+ import Data.Maybe (fromMaybe )
4+
5+ test :: Integer
6+ test = fromMaybe 0 (Just 12 )
7+
You can’t perform that action at this time.
0 commit comments