EuroIT (empty) → 2010.2.5
raw patch · 4 files changed
+99/−0 lines, 4 filesdep +basesetup-changed
Dependencies added: base
Files
- Data/EuroIT.hs +54/−0
- EuroIT.cabal +18/−0
- LICENSE +25/−0
- Setup.hs +2/−0
+ Data/EuroIT.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE ScopedTypeVariables, GeneralizedNewtypeDeriving #-}+module Data.EuroIT where++-- import Text.ParserCombinators.ReadPrec+import Control.Arrow+import Control.Applicative ((<$>))+import Text.ParserCombinators.ReadP+import Text.Read (readPrec, lift)+import Text.Printf+import Data.Ratio+import Data.List+++newtype Euro = Euro Rational deriving (Eq,Num,Ord)++instance Show Euro where+ show (Euro x) = printf "%d euro" y' ++ if yc' > 0 then printf " e %d centesimi" yc' else "" where+ z = truncate $ fromRational (x * 100) :: Int+ (y,yc) = z `divMod` 100 + (y',yc') = if y >= 0 then (y,yc) else + if yc > 0 then (y + 1, 100 - yc) else (y,yc)++afterSpaces x = skipSpaces >> string x+instance Read Euro where+ readPrec = let + com = do+ n <- readS_to_P reads+ optional $ afterSpaces "euro"+ do choice [string ",",afterSpaces "e"]+ c <- readS_to_P reads+ optional $ afterSpaces "centesimi"+ return . Euro $ (n * 100 + if n < 0 then negate c else c) % 100+ <++ (return . Euro $ n % 1)+ bug = do + r <- readS_to_P reads+ return . Euro $ approxRational r 0.01+ in lift $ com <++ bug++newtype DEuro = DEuro (Euro -> Euro)++mkDEuro :: Euro -> DEuro+mkDEuro x = DEuro (+ x)++($^) :: DEuro -> Euro -> Euro+DEuro x $^ y = x y++opposite :: DEuro -> DEuro +opposite f = mkDEuro . negate $ f $^ 0+instance Show DEuro where+ show (DEuro f) = show (f $ fromInteger 0)++instance Read DEuro where+ readPrec = mkDEuro <$> readPrec+
+ EuroIT.cabal view
@@ -0,0 +1,18 @@++name: EuroIT +version: 2010.2.5+license: BSD3+license-file: LICENSE+maintainer: Paolo Veronelli <paolo.veronelli@gmail.com> +stability: unstable+category: Data+synopsis: Library for using euro currency, italian language+description: ..+homepage:+copyright: Copyright (c) 2010 Paolo Veronelli +build-type: Simple+cabal-version: >= 1.6++Build-Depends: base >=4 && <5+Exposed-modules: Data.EuroIT+
+ LICENSE view
@@ -0,0 +1,25 @@+* Copyright (c) 2009, Paolo Veronelli +* 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 the <organization> nor the+* names of its contributors may be used to endorse or promote products+* derived from this software without specific prior written permission.+*+* THIS SOFTWARE IS PROVIDED BY Paolo Veronelli ``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 Paolo Veronelli 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.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain