-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor base library structure and port additional Haskell functions #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
loki259
wants to merge
8
commits into
agda:master
Choose a base branch
from
loki259:refactor-baselib
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2bba3c5
Refactor base library structure and port additional Haskell functions
loki259 e67238c
Fix: whitespace
loki259 5459733
Fix: test with invalid reference to renamed symbol
loki259 b66a5ee
Mark some variables as private to avoid polluting the namespace
loki259 e604278
Expose some private definitions through helper submodules
loki259 822285b
Fix: whitespace
loki259 80f58c2
Introduce submodules for instances of type classes and extract `Semig…
loki259 9f7a890
Replace most Prelude reexports by introducing explicit alias definiti…
loki259 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,29 @@ | ||
| module Haskell.Control.Applicative where | ||
|
|
||
| open import Haskell.Prim | ||
| open import Haskell.Prim.Maybe | ||
|
|
||
| open import Haskell.Prim.Applicative public | ||
| open import Haskell.Prim.Alternative public | ||
| open import Haskell.Data.Functor public using (_<$>_) | ||
| open import Haskell.Data.Foldable public using (asum) | ||
|
|
||
|
|
||
| infixl 4 _<**>_ | ||
| _<**>_ : ⦃ Applicative f ⦄ → f a → f (a → b) → f b | ||
| _<**>_ = liftA2 (λ a f → f a) | ||
|
|
||
| liftA : ⦃ Applicative f ⦄ → (a → b) → f a → f b | ||
| liftA f a = pure f <*> a | ||
|
|
||
| liftA3 : ⦃ Applicative f ⦄ → (a → b → c → d) → f a → f b → f c → f d | ||
| liftA3 f a b c = liftA2 f a b <*> c | ||
|
|
||
| optional : ⦃ Alternative f ⦄ → f a → f (Maybe a) | ||
| optional v = Just <$> v <|> pure Nothing | ||
|
|
||
| -- Omitted for now: | ||
| -- - 'newtype Const a (b :: k) = Const { getConst :: a }' | ||
| -- - 'newtype WrappedMonad (m :: Type -> Type) a = WrapMonad { unwrapMonad :: m a }' | ||
| -- - 'newtype WrappedArrow (a :: Type -> Type -> Type) b c = WrapArrow { unwrapArrow :: a b c }' | ||
| -- - 'newtype ZipList a = ZipList { getZipList :: [a] }' | ||
This file contains hidden or 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 hidden or 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,85 @@ | ||
| module Haskell.Data.Foldable where | ||
|
|
||
| open import Haskell.Prim | ||
| open import Haskell.Prim.Monad | ||
| open import Haskell.Prim.Applicative | ||
| open import Haskell.Prim.Alternative | ||
| open import Haskell.Prim.MonadPlus | ||
| open import Haskell.Prim.Monoid | ||
| open import Haskell.Prim.Eq | ||
| open import Haskell.Prim.Ord | ||
| open import Haskell.Prim.Bool | ||
| open import Haskell.Prim.Maybe | ||
|
|
||
| open import Haskell.Prim.Foldable public | ||
|
|
||
|
|
||
| foldrM : ⦃ Foldable t ⦄ → ⦃ Monad m ⦄ → (a → b → m b) → b → t a → m b | ||
| foldrM f z0 xs = foldl (λ k x z → f x z >>= k) return xs z0 | ||
|
|
||
| foldlM : ⦃ Foldable t ⦄ → ⦃ Monad m ⦄ → (b → a → m b) → b → t a → m b | ||
| foldlM f z0 xs = foldr (λ x k z → f z x >>= k) return xs z0 | ||
|
|
||
| traverse₋ : ⦃ Foldable t ⦄ → ⦃ Applicative f ⦄ → (a → f b) → t a → f ⊤ | ||
| traverse₋ f = foldr (λ x m → f x *> m) (pure tt) | ||
|
|
||
| for₋ : ⦃ Foldable t ⦄ → ⦃ Applicative f ⦄ → t a → (a → f b) → f ⊤ | ||
| for₋ = flip traverse₋ | ||
|
|
||
| mapM₋ : ⦃ Foldable t ⦄ → ⦃ Monad m ⦄ → (a → m b) → t a → m ⊤ | ||
| mapM₋ f = foldr (λ x m → f x >> m) (pure tt) | ||
|
|
||
| forM₋ : ⦃ Foldable t ⦄ → ⦃ Monad m ⦄ → t a → (a → m b) → m ⊤ | ||
| forM₋ = flip mapM₋ | ||
|
|
||
| sequenceA₋ : ⦃ Foldable t ⦄ → ⦃ Applicative f ⦄ → t (f a) → f ⊤ | ||
| sequenceA₋ = foldr (λ mx my → mx *> my) (pure tt) | ||
|
|
||
| sequence₋ : ⦃ Foldable t ⦄ → ⦃ Monad m ⦄ → t (m a) → m ⊤ | ||
| sequence₋ = foldr (λ mx my → mx >> my) (pure tt) | ||
|
|
||
| asum : ⦃ Foldable t ⦄ → ⦃ Alternative f ⦄ → t (f a) → f a | ||
| asum = foldr _<|>_ empty | ||
|
|
||
| msum : ⦃ Foldable t ⦄ → ⦃ MonadPlus m ⦄ → t (m a) → m a | ||
| msum = asum | ||
|
|
||
| concat : ⦃ Foldable t ⦄ → t (List a) → List a | ||
| concat = fold | ||
|
|
||
| concatMap : ⦃ Foldable t ⦄ → (a → List b) → t a → List b | ||
| concatMap = foldMap | ||
|
|
||
| any : ⦃ Foldable t ⦄ → (a → Bool) → t a → Bool | ||
| any ⦃ i ⦄ = foldMap ⦃ i ⦄ ⦃ MonoidDisj ⦄ | ||
|
|
||
| all : ⦃ Foldable t ⦄ → (a → Bool) → t a → Bool | ||
| all ⦃ i ⦄ = foldMap ⦃ i ⦄ ⦃ MonoidConj ⦄ | ||
|
|
||
| and : ⦃ Foldable t ⦄ → t Bool → Bool | ||
| and = all id | ||
|
|
||
| or : ⦃ Foldable t ⦄ → t Bool → Bool | ||
| or = any id | ||
|
|
||
| maximumBy : ⦃ _ : Foldable t ⦄ → (a → a → Ordering) → (s : t a) → @0 ⦃ NonEmpty (toList s) ⦄ → a | ||
| maximumBy {a = a} cmp = foldr1 max' | ||
| where | ||
| max' : a → a → a | ||
| max' x y with cmp x y | ||
| ... | GT = x | ||
| ... | _ = y | ||
|
|
||
| minimumBy : ⦃ _ : Foldable t ⦄ → (a → a → Ordering) → (s : t a) → @0 ⦃ NonEmpty (toList s) ⦄ → a | ||
| minimumBy {a = a} cmp = foldr1 min' | ||
| where | ||
| min' : a → a → a | ||
| min' x y with cmp x y | ||
| ... | GT = y | ||
| ... | _ = x | ||
|
|
||
| notElem : ⦃ Foldable t ⦄ → ⦃ Eq a ⦄ → a → t a → Bool | ||
| notElem x t = not (elem x t) | ||
|
|
||
| find : ⦃ Foldable t ⦄ → (a → Bool) → t a → Maybe a | ||
| find ⦃ i ⦄ p = foldMap ⦃ i ⦄ ⦃ MonoidFirst ⦄ (λ x → if p x then Just x else Nothing) |
This file contains hidden or 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,25 @@ | ||
| module Haskell.Data.Functor where | ||
|
|
||
| open import Haskell.Prim | ||
| open import Haskell.Prim.Tuple | ||
|
|
||
| open import Haskell.Prim.Functor public | ||
|
|
||
|
|
||
| infixl 4 _$>_ | ||
| _$>_ : ⦃ Functor f ⦄ → f a → (@0 ⦃ a ⦄ → b) → f b | ||
| _$>_ = flip _<$_ | ||
|
|
||
| infixl 4 _<$>_ | ||
| _<$>_ : ⦃ Functor f ⦄ → (a → b) → f a → f b | ||
| _<$>_ = fmap | ||
|
|
||
| infixl 1 _<&>_ | ||
| _<&>_ : ⦃ Functor f ⦄ → f a → (a → b) → f b | ||
| m <&> f = fmap f m | ||
|
|
||
| unzip : ⦃ Functor f ⦄ → f (a × b) -> (f a × f b) | ||
| unzip xs = fst <$> xs , snd <$> xs | ||
|
|
||
| void : ⦃ Functor f ⦄ → f a → f ⊤ | ||
| void = tt <$_ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.