strict-data (empty) → 0.1.0.0
raw patch · 5 files changed
+137/−0 lines, 5 filesdep +aesondep +basedep +deepseqsetup-changed
Dependencies added: aeson, base, deepseq, store
Files
- LICENSE +30/−0
- README.md +5/−0
- Setup.hs +2/−0
- src/Data/Option.hs +75/−0
- strict-data.cabal +25/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Alexander Thiemann (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Alexander Thiemann nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,5 @@+# Various strict data structures++This package currently contains strict data structures and usefuly instance for:++* `Data.Option` to replace `Data.Maybe`
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Option.hs view
@@ -0,0 +1,75 @@+{-# LANGUAGE DeriveGeneric #-}+module Data.Option where++import Control.Applicative+import Control.DeepSeq+import Control.Monad+import Data.Aeson+import Data.Store+import GHC.Generics++data Option a+ = None+ | Some !a+ deriving (Show, Eq, Ord, Generic)++instance NFData a => NFData (Option a)+instance Store a => Store (Option a)++instance Functor Option where+ fmap f x =+ case x of+ None -> None+ Some v -> Some (f v)+ {-# INLINE fmap #-}++instance Applicative Option where+ pure = Some+ {-# INLINE pure #-}++ f <*> x =+ case f of+ Some g -> fmap g x+ None -> None+ {-# INLINE (<*>) #-}++instance Monad Option where+ (Some x) >>= k = k x+ None >>= _ = None+ (>>) = (*>)+ fail _ = None++instance Monoid a => Monoid (Option a) where+ mempty = None+ None `mappend` m = m+ m `mappend` None = m+ Some m1 `mappend` Some m2 = Some (m1 `mappend` m2)++instance Alternative Option where+ empty = None+ None <|> r = r+ l <|> _ = l++instance MonadPlus Option++instance ToJSON a => ToJSON (Option a) where+ toJSON = toJSON . optionToMaybe+ {-# INLINE toJSON #-}++instance FromJSON a => FromJSON (Option a) where+ parseJSON x = maybeToOption <$> parseJSON x+ {-# INLINE parseJSON #-}++optionToMaybe :: Option a -> Maybe a+optionToMaybe x =+ case x of+ Some v -> Just v+ None -> Nothing+{-# INLINE optionToMaybe #-}++maybeToOption :: Maybe a -> Option a+maybeToOption x =+ case x of+ Just v -> Some v+ Nothing -> None+{-# INLINE maybeToOption #-}
+ strict-data.cabal view
@@ -0,0 +1,25 @@+name: strict-data+version: 0.1.0.0+synopsis: Verious useful strict data structures+description: Please see README.md+homepage: https://github.com/agrafix/strict-data#readme+license: BSD3+license-file: LICENSE+author: Alexander Thiemann+maintainer: mail@athiemann.net+copyright: 2016 Alexander Thiemann <mail@athiemann.net>+category: Data+build-type: Simple+extra-source-files:+ README.md+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Data.Option+ build-depends: base >= 4.7 && < 5, aeson, store, deepseq+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/agrafix/strict-data