acme-microwave (empty) → 0.1.0.0
raw patch · 4 files changed
+113/−0 lines, 4 filesdep +basesetup-changed
Dependencies added: base
Files
- Data/Microwave.hs +61/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- acme-microwave.cabal +20/−0
+ Data/Microwave.hs view
@@ -0,0 +1,61 @@+-- | Have you ever wondered why, when using a microwave, pressing \"60\" is the same as pressing \"100\"? Well wonder no longer! I, through epic trials and hardships, have tamed the vexacious wiles of that most enigmatic appliance.+--+-- @+-- λ> let n = 200 :: Microwave+-- λ> n+-- 2:00+-- λ> n > 150+-- True+-- λ> n > 170+-- False+-- λ> n \`quotRem\` 7+-- (0:17,0:01)+-- @+module Data.Microwave (Microwave) where++newtype Microwave = Microwave {fromMicrowave :: Integer}++instance Show Microwave where+ show (Microwave n) = let (mins, secs) = n `quotRem` 100+ secs' = case (show secs) of+ [c] -> '0':[c]+ s -> s+ in show mins ++ ":" ++ secs'++instance Read Microwave where+ readsPrec n s = let s' = filter (/= ':') s in map (\(n, r) -> (fixSecs n, r)) $ readsPrec n s'++fixSecs n = let (mins, secs) = n `quotRem` 100+ (carry, secs') = secs `quotRem` 60+ in Microwave (100 * (mins + carry) + secs')++-- turn display time into raw seconds+normalize (Microwave n) = let (mins, secs) = n `quotRem` 100 in 60 * mins + secs++-- turn raw seconds into display time+denormalize n = let (mins, secs) = n `quotRem` 60 in Microwave (100 * mins + secs)++instance Eq Microwave where+ n == m = normalize n == normalize m++instance Ord Microwave where+ n `compare` m = normalize n `compare` normalize m++instance Enum Microwave where+ fromEnum = fromInteger . normalize+ toEnum = denormalize . toInteger++instance Num Microwave where+ fromInteger = fixSecs+ n + m = Microwave (normalize n + normalize m)+ n * m = Microwave (normalize n * normalize m)+ abs = Microwave . abs . fromMicrowave+ signum = Microwave . signum . fromMicrowave++instance Real Microwave where+ toRational = toRational . normalize++instance Integral Microwave where+ toInteger = normalize+ quotRem n m = let (q, r) = quotRem (normalize n) (normalize m) in (denormalize q, denormalize r)+
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Joe Quinn++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 Joe Quinn 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ acme-microwave.cabal view
@@ -0,0 +1,20 @@+-- Initial acme-microwave.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: acme-microwave+version: 0.1.0.0+synopsis: The eighth wonder of the world, kitchen math!+description: Have you ever wondered why, when using a microwave, pressing "60" is the same as pressing "100"? Well wonder no longer! I, through epic trials and hardships, have tamed the vexacious wiles of that most enigmatic appliance.+license: BSD3+license-file: LICENSE+author: Joe Quinn+maintainer: headprogrammingczar@gmail.com+copyright: Joe Quinn+category: Acme+build-type: Simple+cabal-version: >=1.8++library+ exposed-modules: Data.Microwave+ -- other-modules: + build-depends: base ==4.5.*