system-f / papa Goto Github PK
View Code? Open in Web Editor NEWReasonable Haskell default import
Reasonable Haskell default import
I would like papa to support older GHC versions. I'm thinking as far back as GHC 7.4
Some redefined infix operators, such as (>>=)
and (.)
do not have the correct fixity.
Belongs in papa-lens-implement
import Control.Lens
import Data.Monoid
newtype Compose f g a =
Compose (f (g a))
instance (Foldable f, Foldable g) => Foldable (Compose f g) where
foldr f z (Compose x) =
foldr (\a b -> foldr f b a) z x
collapse0 ::
(Cons r r a a, AsEmpty r) =>
Getting (Endo r) s a
-> s
-> r
collapse0 x =
foldrOf x cons (_Empty # ())
collapse1 ::
(Cons r r a a, AsEmpty r) =>
Getting (Endo r) (Compose f g b) a
-> f (g b)
-> r
collapse1 x =
collapse0 x . Compose
collapse2 ::
(Cons r r a a, AsEmpty r) =>
Getting (Endo r) (Compose (Compose f g) h b) a
-> f (g (h b))
-> r
collapse2 x =
collapse1 x . Compose
map1 ::
(Cons r r a a, AsEmpty r, Functor f) =>
Getting (Endo r) (f c) a
-> (b -> c)
-> f b
-> r
map1 x f =
collapse0 x . fmap f
map2 ::
(Cons r r a a, AsEmpty r, Functor f) =>
Getting (Endo r) (Compose f g c) a
-> (b -> g c)
-> f b
-> r
map2 x f =
collapse1 x . fmap f
map3 ::
(Cons r r a a, AsEmpty r, Functor f) =>
Getting (Endo r) (Compose (Compose f g) h c) a
-> (b -> g (h c))
-> f b
-> r
map3 x f =
collapse2 x . fmap f
----
mapMaybe ::
(a -> Maybe b)
-> [a]
-> [b]
mapMaybe =
map2 folded
catMaybes ::
[Maybe a]
-> [a]
catMaybes =
collapse1 folded
minimum, maximum :: (Foldable t, Ord a) => t a -> Maybe a
I know it's nice that you can have mutually recursive definitions of some
and many
, but it seems more correct if the result of some
is NonEmpty
. Thoughts?
Get this one done once and for all.
{-# LANGUAGE FlexibleInstances #-}
import Control.Category(Category(id))
import Control.Lens
import Data.Bool
import Data.Monoid
import Prelude hiding (id)
class GetBool a where
_GetBool ::
Getter a Bool
instance GetBool Bool where
_GetBool =
id
instance GetBool Any where
_GetBool =
_Wrapped
instance GetBool All where
_GetBool =
_Wrapped
instance GetBool (Dual Bool) where
_GetBool =
_Wrapped
instance GetBool (First ()) where
_GetBool =
to (\(First x) -> maybe False (\() -> True) x)
instance GetBool (Last ()) where
_GetBool =
to (\(Last x) -> maybe False (\() -> True) x)
cprogrammer ::
(Contravariant f, Profunctor p, Num a, Functor f, Eq a) =>
Optic' p f a Bool
cprogrammer =
to (== 0)
instance GetBool Int where
_GetBool =
cprogrammer
instance GetBool Integer where
_GetBool =
cprogrammer
instance GetBool Word where
_GetBool =
cprogrammer
instance (Eq a, Num a) => GetBool (Identity a) where
_GetBool =
cprogrammer
instance (Eq a, Num a) => GetBool (Const a b) where
_GetBool =
cprogrammer
instance (Eq a, Num a) => GetBool (Sum a) where
_GetBool =
cprogrammer
instance GetBool Float where
_GetBool =
cprogrammer
instance GetBool Double where
_GetBool =
cprogrammer
class GetBool a => IsBool a where
_Bool ::
Iso' a Bool
instance IsBool Bool where
_Bool =
id
instance IsBool Any where
_Bool =
_Wrapped
instance IsBool All where
_Bool =
_Wrapped
instance IsBool (Dual Bool) where
_Bool =
_Wrapped
instance IsBool (First ()) where
_Bool =
iso
(view _GetBool)
(First . bool Nothing (Just ()))
instance IsBool (Last ()) where
_Bool =
iso
(view _GetBool)
(Last . bool Nothing (Just ()))
true ::
IsBool a =>
a
true =
True ^. from _Bool
false ::
IsBool a =>
a
false =
False ^. from _Bool
if' ::
GetBool a =>
x
-> x
-> a
-> x
if' f t a =
if a ^. _GetBool then t else f
ifB ::
(GetBool a, Monad f) => -- todo use Bind, not Monad
f x
-> f x
-> f a
-> f x
ifB f t a =
a >>= if' f t
(?.) ::
(Category c, IsBool a) =>
c x x
-> a
-> c x x
(?.) =
if' id
(?<>) ::
(Monoid x, IsBool a) =>
x
-> a
-> x
(?<>) =
if' mempty
(?<*>) ::
(Applicative f, GetBool a) =>
(x -> f x)
-> a
-> x
-> f x
(?<*>) =
if' pure
(?@) ::
(Applicative f, GetBool a) =>
f ()
-> a
-> f ()
(?@) =
if' (pure ())
(!?.) ::
(Category c, IsBool a) =>
c x x
-> a
-> c x x
(!?.) =
(`if'` id)
(!?<>) ::
(Monoid x, IsBool a) =>
x
-> a
-> x
(!?<>) =
(`if'` mempty)
(!?<*>) ::
(Applicative f, GetBool a) =>
(x -> f x)
-> a
-> x
-> f x
(!?<*>) =
(`if'` pure)
(!?@) ::
(Applicative f, GetBool a) =>
f ()
-> a
-> f ()
(!?@) =
(`if'` (pure ()))
Papa should be built on all supported GHC versions on every commit. In other projects we're using Travis CI for this, so we should set that up here too.
Implement (>=>)
and (<=<)
using Bind
.
The Control.Monad.Error.Lens
module should be in module Papa
.
All the papa-*
packages do not compile on windows due to the funky Setup.lhs
file and associated funky build configuration.
We should fix this.
I don't really see the motivation and it fragments the haddock.
Move the repository to qfpl/papa
/cc @dalaing
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.