packages feed

ANum 0.1.1.0 → 0.2.0.1

raw patch · 4 files changed

+98/−57 lines, 4 filesdep +ANumdep ~base

Dependencies added: ANum

Dependency ranges changed: base

Files

ANum.cabal view
@@ -1,5 +1,5 @@ name:                ANum-version:             0.1.1.0+version:             0.2.0.1 synopsis:            Num instance for Applicatives provided via the ANum newtype homepage:            https://github.com/DanBurton/ANum#readme bug-reports:         https://github.com/DanBurton/ANum/issues@@ -7,17 +7,26 @@ license-file:        LICENSE author:              Dan Burton maintainer:          dan.burton@originate.com-copyright:           (c) Dan Burton 2013+copyright:           (c) Dan Burton 2013 - 2018 category:            Data build-type:          Simple cabal-version:       >=1.10  library+  default-language:    Haskell2010+  hs-source-dirs:      src   exposed-modules:     Data.ANum   other-extensions:    GeneralizedNewtypeDeriving-  build-depends:       base == 4.*+  build-depends:       base >= 4.8 && < 5   default-language:    Haskell2010 +test-suite ANum-test+  default-language:    Haskell2010+  hs-source-dirs:      test+  main-is:             Main.hs+  type:                exitcode-stdio-1.0+  build-depends:       base, ANum+ source-repository head   type: git   location: git://github.com/DanBurton/ANum.git@@ -25,4 +34,4 @@ source-repository this   type: git   location: git://github.com/DanBurton/ANum.git-  tag: ANum-0.1.1.0+  tag: ANum-0.2.0.1
− Data/ANum.hs
@@ -1,53 +0,0 @@-module Data.ANum (ANum(ANum), unANum) where--import Control.Applicative (Applicative, pure, (<*>), liftA, liftA2)---newtype ANum f n = ANum (f n)-  deriving (Show)--unANum :: ANum f n -> f n-unANum (ANum x) = x---instance (Functor f) => Functor (ANum f) where-  fmap f (ANum x) = ANum (fmap f x)--instance (Applicative f) => Applicative (ANum f) where-  pure x = ANum (pure x)-  (ANum f) <*> (ANum x) = ANum (f <*> x)---instance (Applicative f, Num n) => Num (ANum f n) where-  fromInteger = pure . fromInteger-  (*) = liftA2 (*)-  (+) = liftA2 (+)-  (-) = liftA2 (-)-  negate = liftA negate-  abs = liftA abs-  signum = liftA signum--instance (Applicative f, Fractional n) => Fractional (ANum f n) where-  (/) = liftA2 (/)-  recip = liftA recip-  fromRational = pure . fromRational--instance (Applicative f, Floating n) => Floating (ANum f n) where-  pi = pure pi-  exp = liftA exp-  sqrt = liftA sqrt-  log = liftA log-  (**) = liftA2 (**)-  logBase = liftA2 logBase-  sin = liftA sin-  tan = liftA tan-  cos = liftA cos-  asin = liftA asin-  atan = liftA atan-  acos = liftA acos-  sinh = liftA sinh-  tanh = liftA tanh-  cosh = liftA cosh-  asinh = liftA asinh-  atanh = liftA atanh-  acosh = liftA acosh
+ src/Data/ANum.hs view
@@ -0,0 +1,55 @@+module Data.ANum (ANum(..)) where++import Control.Applicative (Applicative, pure, (<*>), liftA, liftA2)+++newtype ANum f n = ANum { unANum :: f n }+  deriving (Show, Eq, Ord)+++instance (Functor f) => Functor (ANum f) where+  fmap f (ANum x) = ANum (fmap f x)++instance (Applicative f) => Applicative (ANum f) where+  pure x = ANum (pure x)+  (ANum f) <*> (ANum x) = ANum (f <*> x)++instance (Foldable f) => Foldable (ANum f) where+    foldMap f = foldMap f . unANum++instance (Traversable f) => Traversable (ANum f) where+    traverse f = fmap ANum . traverse f . unANum++instance (Applicative f, Num n) => Num (ANum f n) where+  fromInteger = pure . fromInteger+  (*) = liftA2 (*)+  (+) = liftA2 (+)+  (-) = liftA2 (-)+  negate = liftA negate+  abs = liftA abs+  signum = liftA signum++instance (Applicative f, Fractional n) => Fractional (ANum f n) where+  (/) = liftA2 (/)+  recip = liftA recip+  fromRational = pure . fromRational++instance (Applicative f, Floating n) => Floating (ANum f n) where+  pi = pure pi+  exp = liftA exp+  sqrt = liftA sqrt+  log = liftA log+  (**) = liftA2 (**)+  logBase = liftA2 logBase+  sin = liftA sin+  tan = liftA tan+  cos = liftA cos+  asin = liftA asin+  atan = liftA atan+  acos = liftA acos+  sinh = liftA sinh+  tanh = liftA tanh+  cosh = liftA cosh+  asinh = liftA asinh+  atanh = liftA atanh+  acosh = liftA acosh
+ test/Main.hs view
@@ -0,0 +1,30 @@+module Main where++import Data.ANum+import System.Exit (exitFailure)++testResults :: [Bool]+testResults =+  [ unANum (1 + ANum (Just 1)) == Just 2+  , unANum (3 * ANum (Just 5)) == Just 15+  ]++failureCount :: Int+failureCount = length $ filter (== False) testResults++totalTests = length testResults++testsFailed :: IO ()+testsFailed = do+  putStrLn ""+  putStrLn $ show failureCount ++ " of " ++ show totalTests ++ " tests failed."+  exitFailure++testsPassed :: IO ()+testsPassed = do+  putStrLn ""+  putStrLn $ "All " ++ show totalTests ++ " tests passed."+  return ()++main :: IO ()+main = if (failureCount > 0) then testsFailed else testsPassed