packages feed

hascal 1.3 → 1.4.1

raw patch · 5 files changed

+91/−29 lines, 5 filesdep +HUnitsetup-changedPVP ok

version bump matches the API change (PVP)

Dependencies added: HUnit

API changes (from Hackage documentation)

- Hascal: data Complex a :: * -> *

Files

Hascal.hs view
@@ -44,16 +44,12 @@ -- Yeah, that's it. Hascal is really minimalistic. -- And I'm not planning to extend it much. module Hascal (-  -- * Types-  -- |Just re-exporting the 'Complex' data-type for simplicity and comfort.-  Complex,-  -- * Functions-  -- ** Operators+  -- * Operators   operators,-  -- ** Evaluators+  -- * Evaluators   eval,   hascal,-  -- ** Pretty Printers+  -- * Pretty Printers   prettyPrint   ) where @@ -76,7 +72,7 @@ --  -- * subtraction, represented by @\'-\'@, -- --- * multiplication, represented by @\'c\'@,+-- * multiplication, represented by @\'*\'@, --  -- * division, represented by @\'\/\'@, -- @@ -100,26 +96,41 @@             ]  +calc :: (Read t, RealFloat t)+     => [(Char, Complex t -> Complex t -> Complex t)]+     -> String+     -> Maybe (Complex t)+calc []          a = readNumber a+calc l@((c,f):s) a | z /= ""   = case (calc l y,calc l z) of+                                   (Just n,Just m) -> Just (f m n)+                                   _               -> Nothing+                   | otherwise = calc s a+                   where (y,z) = second (drop 1) $ break (==c) a++ -- |'eval' gets a list of operators and a string containing a mathematical -- expression/term which only uses those operators listed in the first -- argument, and returns the result of that term. eval :: (Read t, RealFloat t)-     => [(Char, Complex t -> Complex t -> Complex t)]  -- ^ list of operators-     -> String                                         -- ^ string containing term-     -> Maybe (Complex t)                              -- ^ just result, or nothing-eval []          ('!':a) = ((0:+1)*) <$> findOrRead a-eval []          ('_':a) = negate <$> findOrRead a-eval []          a       = findOrRead a-eval l@((c,f):s) a       | z /= ""   = case (eval l y,eval l z) of-                                         (Just n,Just m) -> Just (f n m)-                                         _               -> Nothing-                         | otherwise = eval s a-                         where (y,z) = second (drop 1) $ break (==c) a+     => [(Char, Complex t -> Complex t -> Complex t)] -- ^ list of operators+     -> String                                        -- ^ string containing term+     -> Maybe (Complex t)                             -- ^ just result, or nothing+eval = (. reverse) . calc  +readNumber :: (Read t, RealFloat t) => String -> Maybe (Complex t)+readNumber ('!':s) = ((0:+1)*) <$> findOrRead s+readNumber ('_':s) =    negate <$> findOrRead s+readNumber      s  =               findOrRead s++ findOrRead :: (Read t, Floating t) => String -> Maybe (Complex t)-findOrRead s = maybe (maybeRead s) (Just . fst) $-               find ((==s) . snd) [(pi:+0,"pi"),(exp 1:+0,"e"),(0:+1,"i")]+findOrRead a = let s = reverse a in+               maybe (maybeRead s) (Just . snd) $ find ((==s) . fst)+               [("pi",pi   :+0)+               ,("e" ,exp 1:+0)+               ,("i" ,0    :+1)+               ]   maybeRead :: (Read t, Num t) => String -> Maybe (Complex t)
Main.hs view
@@ -1,9 +1,11 @@ module Main where  import Control.Monad-import Hascal import System.Environment import Data.Number.CReal+import Data.Complex++import Hascal   main :: IO ()
Setup.hs view
@@ -1,2 +1,6 @@+module Main where+ import Distribution.Simple++main :: IO () main = defaultMain
+ Test.hs view
@@ -0,0 +1,39 @@+import Prelude               hiding (succ)+import Test.HUnit            hiding (test)+import Control.Monad (liftM)+import Data.Complex++import Hascal++++main :: IO Int+main = liftM (\x -> errors x + failures x) (runTestTT tests)++++tests :: Test+tests = TestList+        [ succ "_5"           ((-5):+0)+        , succ "2+7"          (9:+0)+        , succ "3-4"          ((-1):+0)+        , succ "9*8"          (72:+0)+        , succ "9/3"          (3:+0)+        , succ "1+2-3-4+5"    ((1+2-3-4+5):+0)+        , succ "8/4+_2-96^2"  ((8/4-2-96**2):+0)+        ]+++test :: (Read t, RealFloat t, Show t)+     => String -> Maybe (Complex t) -> Test+test string value = TestLabel string $ TestCase $+                    assertEqual string value (hascal string)+++succ :: (Read t, RealFloat t, Show t)+     => String -> Complex t -> Test+succ string value = test string (Just value)+++flop :: String -> t -> Test+flop string value = test string Nothing
hascal.cabal view
@@ -1,21 +1,21 @@ name:          hascal-version:       1.3-synopsis:      A minimal, extensible and precise calculator-description:   Hascal is a minimal calculator with infix-operations+version:       1.4.1+synopsis:      A minimalistic but extensible and precise calculator+description:   Hascal is a minimalistic calculator with infix-operations                supporting addition, subtraction, division, multiplication,                exponentiation and logarithming.                Futhermore, it's easy to add custom operators. stability:     provisional category:      Math, Console, Tools, Utility, Utils, Parsing homepage:      http://darcsden.com/mekeor/hascal-bug-reports:   https://github.com/MekeorMelire/hascal/issues+bug-reports:   http://darcsden.com/mekeor/hascal/issues license:       GPL license-file:  LICENSE copyright:     2012 Mekeor Melire author:        Mekeor Melire <mekeor.melire@googlemail.com> maintainer:    Mekeor Melire <mekeor.melire@googlemail.com>-tested-with:   GHC ==7.0.4-cabal-version: >= 1.6+tested-with:   GHC ==7.4.1+cabal-version: >= 1.8 build-type:    Simple  @@ -29,8 +29,14 @@   location: git://github.com/MekeorMelire/hascal.git  +test-suite test+  type:          exitcode-stdio-1.0+  main-is:       Test.hs+  build-depends: HUnit ==1.2.*+  + library-  build-depends:   base >2 && <5, numbers >= 3000+  build-depends:   base >2 && <5   exposed-modules: Hascal   ghc-options:     -Wall