packages feed

hydrogen-prelude 0.8 → 0.9

raw patch · 5 files changed

+354/−33 lines, 5 filesdep +hydrogen-multimapPVP ok

version bump matches the API change (PVP)

Dependencies added: hydrogen-multimap

API changes (from Hackage documentation)

- Hydrogen.Prelude: for :: Functor f => f a -> (a -> b) -> f b
+ Hydrogen.Prelude: (.^) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
+ Hydrogen.Prelude: (?) :: Container a => a -> Contained a -> Bool
+ Hydrogen.Prelude: class Container a where type family Contained a
+ Hydrogen.Prelude: data MultiMap k v :: * -> * -> *
+ Hydrogen.Prelude: instance Eq a => Container (Seq a)
+ Hydrogen.Prelude: instance Eq a => Container [a]
+ Hydrogen.Prelude: instance Ord a => Container (Set a)
+ Hydrogen.Prelude: instance Ord k => Container (Map k v)
+ Hydrogen.Prelude: instance Ord k => Container (MultiMap k v)
+ Hydrogen.Prelude: instance Ord k => Has (MultiMap k v)
+ Hydrogen.Prelude: instance TMap (MultiMap k v)
+ Hydrogen.Prelude: map :: Functor f => (a -> b) -> f a -> f b
- Hydrogen.Prelude: (!) :: Has a => a -> K a -> V a
+ Hydrogen.Prelude: (!) :: Has a => a -> HasKey a -> HasValue a
- Hydrogen.Prelude: class Has a where type family K a type family V a
+ Hydrogen.Prelude: class Has a where type family HasKey a type family HasValue a

Files

CHANGELOG.md view
@@ -1,6 +1,5 @@ ## v0.1 + initial release-+ ***deprecated***  ## v0.1.0.1 + Patch: Modules were not properly exported in Cabal file@@ -15,7 +14,7 @@ + Added CHANGELOG.md to source package  ## v0.2.1-+ Added __++ Added `__` (short hand for `undefined`)  ## v0.3 + Also exports@@ -27,4 +26,38 @@ + New dependency on `hydrogen-version`   + Exports `module Hydrogen.Version` as replacement for `module Data.Version` +## v0.4+*Skipped, bumped to v0.5 to be aligned with other hydrogen packages*++## v0.5++ Deriving instance `Eq` for `ZonedTime`++## v0.6++ New dependencies+  + `cereal` for serialization+  + `strict` for strict io in `Hydrogen.Prelude.IO`++ Also exports+  + `module Data.Dynamic`+  + `module Data.Typeable`++ Added `ShowBox` class (an existentially qualified container type)++## v0.7++ Newly deriving instances+  + `Serialize` for `ZonedTime`+  + `Serialize` for `Version`++## v0.8++ Added `class TMap (tmap)` and `class Has (HasKey, HasValue, (!))`++ Introduced `type List a` as alias for `[a]`++ Also exports+  + `Data.Seq`++ Added the F-Sharp inspired `|>` (which is `flip ($)`)++ Exporting only `Generic` from `GHC.Generics`++ Added `Hydrogen.Prelude.Network`++## v0.9++ Also exports+  + `module Data.Traversable`++ Added `class Container (Contained, (?))`++ `fmap` is exported as `map` 
README.md view
@@ -1,3 +1,228 @@+hydrogen-prelude+================ ++ [`about`](#about)+  + [`scravy.de/hydrogen-prelude`](http://scravy.de/hydrogen-prelude)+  + [`hackage.haskell.org/package/hydrogen-prelude`](http://hackage.haskell.org/package/hydrogen-prelude)++ [`goodies`](#goodies)+  + [`(!)`](#--has-a--a--haskey-a--hasvalue-a)+  + [`(?)`](#--container-a--a--contained-a--bool)+  + [`tmap`](#tmap)+  + [`fmap` vs `map`](#fmap-vs-map)+  + [`__`](#__--a)+  + [`|>`](#fsharps--which-is-flip-)+  + [`safeHead`](#safehead--a--a--a)+  + [`ShowBox`](#showbox--forall-a-show-a--a--showbox)+  + [`.|`, `.&`, `.^`](#----a--bool--a--bool--a--bool)+  + [`List a`](#type-list-a--a)++ [`re-exports`](#re-exports)+  + [`Hydrogen.Prelude`](#hydrogenprelude)+  + [`Hydrogen.Prelude.IO`](#hydrogenpreludeio)+  + [`Hydrogen.Prelude.System`](#hydrogenpreludesystem)+  + [`Hydrogen.Prelude.Network`](#hydrogenpreludenetwork)++ [`FAQ`](#faq)++about+-----++A Prelude that exports much of the standard library (more then `Prelude`), without conflicts. If for example you were to import `Prelude` and `Data.List` or `Data.Foldable` you will run into ambiguous imports (regarding `foldr` for example). This Prelude aims at exporting the most general functions (in this case `foldr` from `Data.Foldable`).++It also pulls in some default packages like `cereal` for serialization and `containers` for data types like `Map` and `Set`. Every datatype exported by this Prelude comes with instances for `Serialize`.++Longs story short, instead of:++    import Prelude hiding (+      all, and, any, concat, concatMap, elem, foldl, foldl1, foldr, foldr1,+      mapM, mapM_, maximum, minimum, notElem, or, product, sequence, sequence_, sum+     )+    import "base" Control.Monad hiding (+      forM, forM_, mapM, mapM_, msum, sequence, sequence_+     )+    import Data.Foldable+    import Data.Traversable+    import Data.List hiding (+      all, and, any, concat, concatMap, elem, find, foldl, foldl', foldl1, foldr, foldr1,+      mapAccumL, mapAccumR, maximum, maximumBy, minimum, minimumBy, notElem, or, product, sum+     )+    +it suffices to:++    import Hydrogen.Prelude++goodies+-------++Beyond existing functions from well-known standard packages, this prelude defines a few utilities (mostly aimed at unifying functionality across different packages, like `containers` and `array`).++### `(!) :: Has a ⇒ a → HasKey a → HasValue a`++`(!)` is provided for several data types which associate a key and a value.++    [(1, 'a'), (3, 'v')] ! 1  →  'a'++Instances are defined for+++ `Eq k ⇒ [(k, v)]`++ `Ix i ⇒ Array i e` with `HasKey → i`++ `Ord k ⇒ Map k v` with `HasValue → v`++ `Ord k ⇒ MultiMap k v` with `HasValue → [v]`++### `(?) :: Container a ⇒ a → Contained a → Bool`++Check whether the element on the right is contained in the collection on the left.++    [1, 2, 4] ? 3  →  False++Instances are defined for+++ `Eq a ⇒ [a]`++ `Ord a ⇒ Set a`++ `Eq a ⇒ Seq a`++ `Ord k ⇒ Map k v` with `Contained → k`++ `Ord k ⇒ MultiMap k v` with `Contained → k`++### `tmap`++A little bit like `fmap` but defined differently on some datatypes (applies e.g. to both components of a tuple).++    tmap succ (3, 4)  →  (4, 5)++Instances are defined for+++ `(a, a)`++ `(a, a, a)`++ `(a, a, a, a)`++ `[a]`++ `Seq a`++ `Map k v`++ `MultiMap k v`++### `fmap` vs `map`++Hydrogen Prelude exports `fmap` as `map` - the way it ought to be.++### `__ :: a`++A handy shortcut for `undefined`.++### FSharp's `|>` (which is `flip ($)`)++Use it to pipe things from one function to the other, left to right:++    head xs |> fromEnum |> show++### `safeHead :: a → [a] → a`++The head of the list, or the default given as first argument.++    safeHead x xs = maybe x head . listToMaybe++### `ShowBox :: forall a. (Show a) ⇒ a → ShowBox` ###++Wrap anything that is showable (can be used to build heterogeneous lists).++### `.|, .&, .^ :: (a → Bool) → (a → Bool) → (a → Bool)`++Combines predicates.++    filter (isDigit .| isLetter)++### `type List a = [a]`++A shorthand for the type of lists, if you prefer this more wordy version.++re-exports+----------++### Hydrogen.Prelude++The Hydrogen Prelude offers you the functions and datatypes from these modules, all with one import:+++ from `base`+  + `module Prelude`+  + `module Control.Applicative`+  + `module Control.Arrow`+  + `module Control.Monad`+  + `module Data.Bits`+  + `module Data.Bool`+  + `module Data.Char`+  + `module Data.Complex`+  + `module Data.Complex`+  + `module Data.Dynamic`+  + `module Data.Either`+  + `module Data.Fixed`+  + `module Data.Function`+  + `module Data.Foldable`+  + `module Data.Int`+  + `module Data.Ix`+  + `module Data.List`+  + `module Data.Maybe`+  + `module Data.Ord`+  + `module Data.Ratio`+  + `module Data.String`+  + `module Data.Time`+  + `module Data.Traversable`+  + `module Data.Tuple`+  + `module Data.Typeable`+  + `module Data.Word`+  + `module Numeric`+  + `module Text.Printf`+++ from `array`+  + `module Data.Array`+++ from `cereal`+  + `module Data.Serialize`+++ from `containers`+  + `Data.Set`, `Data.Map`, and `Data.Seq`+++ from `hashable`+  + `module Data.Hashable`+++ form `hydrogen-multimap`+  + `Hydrogen.MultiMap`+++ from `hydrogen-version`+  + `module Hydrogen.Version`+++ from `regex-tdfa`+  + `module Text.Regex.TDFA`+++ from `time`+  + `module Data.Time`+++ from `transformers`+  + `module Data.Functor.Identity`+  + `module Data.Functor.Reverse`+++ from `uuid`+  + `Data.UUID`+  + `Data.UUID.fromString` as `uuidFromString`+  + `Data.UUID.V4.nextRandom` as `randomUUID`++### Hydrogen.Prelude.IO++### Hydrogen.Prelude.System++### Hydrogen.Prelude.Network++FAQ+===++How is some of the *magic* accomplished?+----------------------------------------++Mostly with `XTypeFamilies` and `XStandaloneDeriving`.++So this works only with GHC?+----------------------------++Yes, for now at least.++What is `hydrogen`+------------------++https://www.youtube.com/watch?v=rbBX6aEzEz8  
hydrogen-prelude.cabal view
@@ -1,8 +1,8 @@ name:                 hydrogen-prelude-version:              0.8-homepage:             https://scravy.de/hydrogen-prelude/+version:              0.9+homepage:             http://scravy.de/hydrogen-prelude/ synopsis:             Hydrogen Prelude-license:              BSD3+license:              MIT license-file:         LICENSE extra-source-files:   CHANGELOG.md, README.md author:               Julian Fleischer@@ -27,6 +27,7 @@                       , directory ==1.2.*                       , filepath ==1.3.*                       , hashable ==1.2.*+                      , hydrogen-multimap ==0.1                       , hydrogen-version >=1.2                       , network >=2.4.2.2                       , process ==1.2.*@@ -42,8 +43,10 @@   default-language:   Haskell2010   default-extensions: CPP                       , DeriveDataTypeable+                      , DeriveFoldable                       , DeriveFunctor                       , DeriveGeneric+                      , DeriveTraversable                       , EmptyCase                       , FlexibleInstances                       , FlexibleContexts
src/Hydrogen/Prelude.hs view
@@ -27,6 +27,7 @@   , module Data.Serialize   , module Data.String   , module Data.Time+  , module Data.Traversable   , module Data.Tuple   , module Data.Typeable   , module Data.Word@@ -35,22 +36,25 @@   , module Text.Printf   , (.&)   , (.|)+  , (.^)   , (=~)   , (=~~)   , (|>)-  , for   , uuidFromString   , randomUUID   , safeHead+  , map   , UUID   , Generic   , List   , Map-  , Set+  , MultiMap   , Seq+  , Set   , ShowBox   , TMap (..)   , Has (..)+  , Container (..)   , __   ) where @@ -65,12 +69,15 @@   , foldl1   , foldr   , foldr1+  , map+  , mapM   , mapM_   , maximum   , minimum   , notElem   , or   , product+  , sequence   , sequence_   , sum   )@@ -78,9 +85,12 @@ import "base" Control.Applicative import "base" Control.Arrow import "base" Control.Monad hiding (-    forM_+    forM+  , forM_+  , mapM   , mapM_   , msum+  , sequence   , sequence_   ) @@ -114,9 +124,12 @@   , foldl1   , foldr   , foldr1+  , map+  , mapAccumL+  , mapAccumR   , maximum-  , minimum   , maximumBy+  , minimum   , minimumBy   , notElem   , or@@ -129,6 +142,7 @@ import "cereal" Data.Serialize import "base" Data.String import "time" Data.Time+import "base" Data.Traversable import "base" Data.Tuple import "base" Data.Typeable import "base" Data.Word@@ -143,10 +157,11 @@ import "containers" Data.Map (Map) import qualified "containers" Data.Map as Map import "containers" Data.Set (Set)--- import qualified "containers" Data.Set as Set+import qualified "containers" Data.Set as Set import "containers" Data.Sequence (Seq)--- import qualified "containers" Data.Sequence as Seq +import "hydrogen-multimap" Hydrogen.MultiMap (MultiMap)+import qualified "hydrogen-multimap" Hydrogen.MultiMap as MultiMap import "hydrogen-version" Hydrogen.Version  import "uuid" Data.UUID (UUID)@@ -190,16 +205,14 @@ instance Show ShowBox where     show (ShowBox a) = show a -(.|), (.&) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)+(.|), (.&), (.^) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool) f .| g = \x -> f x || g x f .& g = \x -> f x && g x+f .^ g = \x -> f x /= g x  (|>) :: a -> (a -> b) -> b (|>) = flip ($) -for :: Functor f => f a -> (a -> b) -> f b-for = flip fmap- __ :: a __ = error "Hydrogen.Prelude.undefined" @@ -214,6 +227,8 @@     x : _ -> x     _     -> d +map :: Functor f => (a -> b) -> f a -> f b+map = fmap  class TMap a where @@ -249,15 +264,22 @@     type Component [a] = a     type Transform ((a -> b) -> [a]) = [b] -    tmap = map+    tmap = fmap  instance TMap (Map k v) where      type Component (Map k v) = v     type Transform ((v -> w) -> Map k v) = Map k w -    tmap = Map.map+    tmap = fmap +instance TMap (MultiMap k v) where++    type Component (MultiMap k v) = v+    type Transform ((v -> w) -> MultiMap k v) = MultiMap k w++    tmap = fmap+ instance TMap (Seq a) where      type Component (Seq a) = a@@ -270,23 +292,23 @@  class Has a where -    type K a-    type V a+    type HasKey a+    type HasValue a -    (!) :: a -> K a -> V a+    (!) :: a -> HasKey a -> HasValue a   instance Ord k => Has (Map k v) where -    type K (Map k v) = k-    type V (Map k v) = v+    type HasKey (Map k v) = k+    type HasValue (Map k v) = v      (!) = (Map.!)  instance Eq k => Has [(k, v)] where -    type K [(k, v)] = k-    type V [(k, v)] = v+    type HasKey [(k, v)] = k+    type HasValue [(k, v)] = v      list ! key = maybeKey (lookup key list)       where@@ -294,9 +316,54 @@  instance Ix i => Has (Array i e) where -    type K (Array i e) = i-    type V (Array i e) = e+    type HasKey (Array i e) = i+    type HasValue (Array i e) = e      (!) = (Array.!)++instance Ord k => Has (MultiMap k v) where++    type HasKey (MultiMap k v) = k+    type HasValue (MultiMap k v) = [v]++    (!) = flip MultiMap.lookup+++class Container a where++    type Contained a++    (?) :: a -> Contained a -> Bool+++instance Ord a => Container (Set a) where++    type Contained (Set a) = a++    (?) = flip Set.member++instance Eq a => Container [a] where++    type Contained [a] = a++    (?) = flip elem++instance Eq a => Container (Seq a) where++    type Contained (Seq a) = a++    c ? e = any (== e) c++instance Ord k => Container (Map k v) where++    type Contained (Map k v) = k++    (?) = flip Map.member++instance Ord k => Container (MultiMap k v) where++    type Contained (MultiMap k v) = k++    (?) = flip MultiMap.member  
src/Hydrogen/Prelude/IO.hs view
@@ -2,7 +2,6 @@     module Hydrogen.Prelude   , module Control.Concurrent   , module Control.Exception-  , module Control.Monad   , module Data.IORef   , module System.IO   , module System.Timeout@@ -18,12 +17,6 @@  import "base" Control.Concurrent import "base" Control.Exception-import "base" Control.Monad hiding (-    forM_-  , mapM_-  , msum-  , sequence_-  )  import "base" System.IO import "base" System.Timeout