forked from agda/agda2hs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ fix agda#377 ] Add module Haskell.Data.Maybe with fromMaybe and more
- Loading branch information
1 parent
32449ab
commit af154f8
Showing
8 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Haskell.Data.Maybe where | ||
|
||
open import Haskell.Prelude | ||
|
||
isJust : Maybe a → Bool | ||
isJust Nothing = False | ||
isJust (Just _) = True | ||
|
||
isNothing : Maybe a → Bool | ||
isNothing Nothing = True | ||
isNothing (Just _) = False | ||
|
||
fromJust : (x : Maybe a) → @0 {IsJust x} → a | ||
fromJust Nothing = error "fromJust Nothing" | ||
fromJust (Just x) = x | ||
|
||
fromMaybe : {a : Set} → a → Maybe a → a | ||
fromMaybe d Nothing = d | ||
fromMaybe _ (Just x) = x | ||
|
||
listToMaybe : List a → Maybe a | ||
listToMaybe [] = Nothing | ||
listToMaybe (x ∷ _) = Just x | ||
|
||
maybeToList : Maybe a → List a | ||
maybeToList Nothing = [] | ||
maybeToList (Just x) = x ∷ [] | ||
|
||
mapMaybe : (a → Maybe b) → List a → List b | ||
mapMaybe f [] = [] | ||
mapMaybe f (x ∷ xs) = maybe id _∷_ (f x) (mapMaybe f xs) | ||
|
||
catMaybes : List (Maybe a) → List a | ||
catMaybes = mapMaybe id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Issue377 where | ||
|
||
open import Haskell.Prelude | ||
open import Haskell.Data.Maybe | ||
|
||
test : Integer | ||
test = fromMaybe 0 (Just 12) | ||
|
||
{-# COMPILE AGDA2HS test #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,5 @@ import FunCon | |
import Issue308 | ||
import Issue324 | ||
import Assert | ||
import Issue377 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Issue377 where | ||
|
||
import Data.Maybe (fromMaybe) | ||
|
||
test :: Integer | ||
test = fromMaybe 0 (Just 12) | ||
|