plailude 0.2.2 → 0.3.0
raw patch · 18 files changed
+240/−188 lines, 18 filesdep +mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: mtl
API changes (from Hackage documentation)
+ Plailude: erretreat :: (MonadError e m, MonadError e n) => m a -> m (n a)
+ Plailude: retreat :: (Monad m, Monad n) => m a -> m (n a)
Files
- plailude.cabal +11/−8
- src/Data/Text.hs +0/−12
- src/Data/Text/Show.hs +0/−15
- src/Data/Time.hs +0/−24
- src/Data/Time/Conversion.hs +0/−30
- src/Data/Time/Units.hs +0/−57
- src/Function.hs +0/−13
- src/Function/Compose.hs +0/−25
- src/Plailude.hs +8/−4
- src/Plailude/Control.hs +13/−0
- src/Plailude/Control/Monad.hs +30/−0
- src/Plailude/Data/Text.hs +12/−0
- src/Plailude/Data/Text/Show.hs +15/−0
- src/Plailude/Data/Time.hs +24/−0
- src/Plailude/Data/Time/Conversion.hs +32/−0
- src/Plailude/Data/Time/Units.hs +57/−0
- src/Plailude/Function.hs +13/−0
- src/Plailude/Function/Compose.hs +25/−0
plailude.cabal view
@@ -1,5 +1,5 @@ name: plailude-version: 0.2.2+version: 0.3.0 synopsis: plaimi's prelude description: The prelude used internally at plaimi. @@ -22,16 +22,19 @@ library exposed-modules: Plailude- other-modules: Data.Text- Data.Text.Show- Data.Time- Data.Time.Conversion- Data.Time.Units- Function- Function.Compose+ other-modules: Plailude.Control+ Plailude.Control.Monad+ Plailude.Data.Text+ Plailude.Data.Text.Show+ Plailude.Data.Time+ Plailude.Data.Time.Conversion+ Plailude.Data.Time.Units+ Plailude.Function+ Plailude.Function.Compose other-extensions: GeneralizedNewtypeDeriving build-depends: base >=4.6 && <4.8, bytestring >=0.10 && <0.11,+ mtl >=2.2.1 && <2.2.2, time >=1.4 && <1.5 hs-source-dirs: src default-language: Haskell2010
− src/Data/Text.hs
@@ -1,12 +0,0 @@-{- |-Module : $Header$-Description : Text manipulation.-Copyright : (c) plaimi 2014-License : GPL-3--Maintainer : plailude@plaimi.net--} module Data.Text (- showL8- ) where--import Data.Text.Show
− src/Data/Text/Show.hs
@@ -1,15 +0,0 @@-{- |-Module : $Header$-Description : Show various Text formats.-Copyright : (c) plaimi 2014-License : GPL-3--Maintainer : plailude@plaimi.net--} module Data.Text.Show where--import qualified Data.ByteString.Lazy as L-import qualified Data.ByteString.Lazy.Char8 as L8--showL8 :: Show a => a -> L.ByteString--- | 'showL8' converts a showable value to a 'L.ByteString' using 'show'.-showL8 = L8.pack . show
− src/Data/Time.hs
@@ -1,24 +0,0 @@-{- |-Module : $Header$-Description : Time representation and manipulation.-Copyright : (c) plaimi 2014-License : GPL-3--Maintainer : plailude@plaimi.net--} module Data.Time (- -- Time.Conversion- asSeconds,- fromGregorian,- -- Time.Units- TimeUnit,- timeVal,- Year (MkYear),- Month (MkMonth),- Day (MkDay),- Hour (MkHour),- Minute (MkMinute),- Second (MkSecond)- ) where--import Data.Time.Conversion-import Data.Time.Units
− src/Data/Time/Conversion.hs
@@ -1,30 +0,0 @@-{- |-Module : $Header$-Description : Converting between time units.-Copyright : (c) plaimi 2014-License : GPL-3--Maintainer : plailude@plaimi.net--} module Data.Time.Conversion where--import qualified Data.Time.Calendar as C--import Data.Time.Units- (Day- ,Hour- ,Minute- ,Month- ,Second (MkSecond)- ,Year- ,timeVal)--fromGregorian :: Year y -> Month mo -> Day d -> C.Day--- | fromGregorian is a wrapper for Data.Time.Calendar.fromGregorian, which--- lets us pass our 'Year' - 'Month' - 'Day' structures. It calls--- Data.Time.Calendar.fromGregorian with the appropriate types, and returns--- a Data.Time.Calendar.Day.-fromGregorian y mo s = C.fromGregorian (timeVal y) (timeVal mo) (timeVal s)--asSeconds :: Hour h -> Minute m -> Second s -> Second t--- | asSeconds take some 'TimeUnit's and convert them to 'Second's.-asSeconds h m s = MkSecond $ 3600 * timeVal h + 60 * timeVal m + timeVal s
− src/Data/Time/Units.hs
@@ -1,57 +0,0 @@-{-# LANGUAGE GeneralizedNewtypeDeriving #-}--{- |-Module : $Header$-Description : Time units.-Copyright : (c) plaimi 2014-License : GPL-3--Maintainer : plailude@plaimi.net--} module Data.Time.Units where---- | 'TimeUnit's are units of time with a value that's an instance of 'Num'.--- The class is used to get type safety of time units, and a function for--- getting "out" the value (analogues to 'fromJust' for 'Maybe') for every--- type of 'Num', for free.-class TimeUnit t where- -- | Get out the value in a 'TimeUnit'. The value's type is- -- polymorphic and constrained to 'Num'.- timeVal :: Num n => t -> n--instance TimeUnit Int where- -- | The value of a 'TimeUnit' 'Int' is simply the 'Int' value.- timeVal = fromInteger . toInteger--instance TimeUnit Integer where- -- | The value of a 'TimeUnit' 'Integer' is simply the 'Integer' value.- timeVal = fromInteger---- | A 'Year' type, for type safety of time units.-newtype Year a =- -- | Make a 'Year', an 'Integer' deriving 'TimeUnit'.- MkYear Integer deriving TimeUnit---- | A 'Month' type, for type safety of time units.-newtype Month a =- -- | Make a 'Month', an 'Int' deriving 'TimeUnit'.- MkMonth Int deriving TimeUnit---- | A 'Day' type, for type safety of time units.-newtype Day a =- -- | Make a 'Day', an 'Int' deriving 'TimeUnit'.- MkDay Int deriving TimeUnit---- | A 'Hour' type, for type safety of time units.-newtype Hour a =- -- | Make an 'Hour', an 'Int' deriving 'TimeUnit'.- MkHour Int deriving TimeUnit---- | A 'Minute' type, for type safety of time units.-newtype Minute a =- -- | Make a 'Minute', an 'Int' deriving 'TimeUnit'.- MkMinute Int deriving TimeUnit---- | A 'Second' type, for type safety of time units.-newtype Second a =- -- | Make a 'Second', an 'Int' deriving 'TimeUnit'.- MkSecond Int deriving TimeUnit
− src/Function.hs
@@ -1,13 +0,0 @@-{- |-Module : $Header$-Description : Function functions.-Copyright : (c) plaimi 2014-License : GPL-3--Maintainer : plailude@plaimi.net--} module Function (- (.:),- (.:.)- ) where--import Function.Compose
− src/Function/Compose.hs
@@ -1,25 +0,0 @@-{- |-Module : $Header$-Description : Mathematical compositions.-Copyright : (c) plaimi 2014-License : GPL-3--Maintainer : plailude@plaimi.net--} module Function.Compose where---- (.) :: (b -> c) -> (a -> b) -> a -> c--- (f . g) x = f (g x)--(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d--- | Compose two functions where the second function takes two values and--- delivers its result as a single value to the first function.------ This is equivalent to: (f .: g) x y = f (g x y).-(.:) = (.).(.)--(.:.) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e--- | Compose two functions where the second function takes three values and--- delivers its result as a single value to the first function.------ This is equivalent to: (f .:. g) x y z = f (g x y z).-(.:.) = (.).(.:)
src/Plailude.hs view
@@ -6,6 +6,9 @@ Maintainer : plailude@plaimi.net -} module Plailude (+ -- Control+ erretreat,+ retreat, -- Function (.:), (.:.),@@ -22,8 +25,9 @@ asSeconds, fromGregorian, timeVal,-) where+ ) where -import Data.Text-import Data.Time-import Function+import Plailude.Control+import Plailude.Data.Text+import Plailude.Data.Time+import Plailude.Function
+ src/Plailude/Control.hs view
@@ -0,0 +1,13 @@+{- |+Module : $Header$+Description : Higher-kinded stuff.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Control (+ erretreat,+ retreat,+ ) where++import Plailude.Control.Monad
+ src/Plailude/Control/Monad.hs view
@@ -0,0 +1,30 @@+{- |+Module : $Header$+Description : Monads. dealwithit.jpeg.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Control.Monad where++import Control.Monad+ (+ liftM,+ )+import Control.Monad.Except+ (+ MonadError,+ catchError,+ throwError,+ )++retreat :: (Monad m, Monad n) => m a -> m (n a)+-- | Retreat the value a of a 'Monad' m further into the 'Monad' burrito by+-- injecting it into yet another 'Monad' n, giving us m (n a).+retreat = liftM return++erretreat :: (MonadError e m, MonadError e n) => m a -> m (n a)+-- | 'retreat' the value a of a 'MonadError' m further into the 'MonadError'+-- burrito by injecting it into yet another 'MonadError' n, giving us m (n a).+-- If there's an error, it is rethrown inside n.+erretreat a = retreat a `catchError` (return . throwError)
+ src/Plailude/Data/Text.hs view
@@ -0,0 +1,12 @@+{- |+Module : $Header$+Description : Text manipulation.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Data.Text (+ showL8,+ ) where++import Plailude.Data.Text.Show
+ src/Plailude/Data/Text/Show.hs view
@@ -0,0 +1,15 @@+{- |+Module : $Header$+Description : Show various Text formats.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Data.Text.Show where++import qualified Data.ByteString.Lazy as L+import qualified Data.ByteString.Lazy.Char8 as L8++showL8 :: Show a => a -> L.ByteString+-- | 'showL8' converts a showable value to a 'L.ByteString' using 'show'.+showL8 = L8.pack . show
+ src/Plailude/Data/Time.hs view
@@ -0,0 +1,24 @@+{- |+Module : $Header$+Description : Time representation and manipulation.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Data.Time (+ -- Time.Conversion+ asSeconds,+ fromGregorian,+ -- Time.Units+ TimeUnit,+ timeVal,+ Year (MkYear),+ Month (MkMonth),+ Day (MkDay),+ Hour (MkHour),+ Minute (MkMinute),+ Second (MkSecond),+ ) where++import Plailude.Data.Time.Conversion+import Plailude.Data.Time.Units
+ src/Plailude/Data/Time/Conversion.hs view
@@ -0,0 +1,32 @@+{- |+Module : $Header$+Description : Converting between time units.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Data.Time.Conversion where++import qualified Data.Time.Calendar as C++import Plailude.Data.Time.Units+ (+ Day,+ Hour,+ Minute,+ Month,+ Second (MkSecond),+ Year,+ timeVal,+ )++fromGregorian :: Year y -> Month mo -> Day d -> C.Day+-- | fromGregorian is a wrapper for Data.Time.Calendar.fromGregorian, which+-- lets us pass our 'Year' - 'Month' - 'Day' structures. It calls+-- Data.Time.Calendar.fromGregorian with the appropriate types, and returns+-- a Data.Time.Calendar.Day.+fromGregorian y mo s = C.fromGregorian (timeVal y) (timeVal mo) (timeVal s)++asSeconds :: Hour h -> Minute m -> Second s -> Second t+-- | asSeconds take some 'TimeUnit's and convert them to 'Second's.+asSeconds h m s = MkSecond $ 3600 * timeVal h + 60 * timeVal m + timeVal s
+ src/Plailude/Data/Time/Units.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++{- |+Module : $Header$+Description : Time units.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Data.Time.Units where++-- | 'TimeUnit's are units of time with a value that's an instance of 'Num'.+-- The class is used to get type safety of time units, and a function for+-- getting "out" the value (analogues to 'fromJust' for 'Maybe') for every+-- type of 'Num', for free.+class TimeUnit t where+ -- | Get out the value in a 'TimeUnit'. The value's type is+ -- polymorphic and constrained to 'Num'.+ timeVal :: Num n => t -> n++instance TimeUnit Int where+ -- | The value of a 'TimeUnit' 'Int' is simply the 'Int' value.+ timeVal = fromInteger . toInteger++instance TimeUnit Integer where+ -- | The value of a 'TimeUnit' 'Integer' is simply the 'Integer' value.+ timeVal = fromInteger++-- | A 'Year' type, for type safety of time units.+newtype Year a =+ -- | Make a 'Year', an 'Integer' deriving 'TimeUnit'.+ MkYear Integer deriving TimeUnit++-- | A 'Month' type, for type safety of time units.+newtype Month a =+ -- | Make a 'Month', an 'Int' deriving 'TimeUnit'.+ MkMonth Int deriving TimeUnit++-- | A 'Day' type, for type safety of time units.+newtype Day a =+ -- | Make a 'Day', an 'Int' deriving 'TimeUnit'.+ MkDay Int deriving TimeUnit++-- | A 'Hour' type, for type safety of time units.+newtype Hour a =+ -- | Make an 'Hour', an 'Int' deriving 'TimeUnit'.+ MkHour Int deriving TimeUnit++-- | A 'Minute' type, for type safety of time units.+newtype Minute a =+ -- | Make a 'Minute', an 'Int' deriving 'TimeUnit'.+ MkMinute Int deriving TimeUnit++-- | A 'Second' type, for type safety of time units.+newtype Second a =+ -- | Make a 'Second', an 'Int' deriving 'TimeUnit'.+ MkSecond Int deriving TimeUnit
+ src/Plailude/Function.hs view
@@ -0,0 +1,13 @@+{- |+Module : $Header$+Description : Function functions.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Function (+ (.:),+ (.:.),+ ) where++import Plailude.Function.Compose
+ src/Plailude/Function/Compose.hs view
@@ -0,0 +1,25 @@+{- |+Module : $Header$+Description : Mathematical compositions.+Copyright : (c) plaimi 2014+License : GPL-3++Maintainer : plailude@plaimi.net+-} module Plailude.Function.Compose where++-- (.) :: (b -> c) -> (a -> b) -> a -> c+-- (f . g) x = f (g x)++(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d+-- | Compose two functions where the second function takes two values and+-- delivers its result as a single value to the first function.+--+-- This is equivalent to: (f .: g) x y = f (g x y).+(.:) = (.).(.)++(.:.) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e+-- | Compose two functions where the second function takes three values and+-- delivers its result as a single value to the first function.+--+-- This is equivalent to: (f .:. g) x y z = f (g x y z).+(.:.) = (.).(.:)