nats-0.1.2/0000755000000000000000000000000012216113454010644 5ustar0000000000000000nats-0.1.2/.ghci0000644000000000000000000000012512216113454011555 0ustar0000000000000000:set -isrc -idist/build/autogen -optP-include -optPdist/build/autogen/cabal_macros.h nats-0.1.2/.gitignore0000644000000000000000000000010412216113454012627 0ustar0000000000000000dist docs wiki TAGS tags wip .DS_Store .*.swp .*.swo *.o *.hi *~ *# nats-0.1.2/.travis.yml0000644000000000000000000000033112216113454012752 0ustar0000000000000000language: haskell notifications: irc: channels: - "irc.freenode.org#haskell-lens" skip_join: true template: - "\x0313nats\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}" nats-0.1.2/.vim.custom0000644000000000000000000000137712216113454012761 0ustar0000000000000000" Add the following to your .vimrc to automatically load this on startup " if filereadable(".vim.custom") " so .vim.custom " endif function StripTrailingWhitespace() let myline=line(".") let mycolumn = col(".") silent %s/ *$// call cursor(myline, mycolumn) endfunction " enable syntax highlighting syntax on " search for the tags file anywhere between here and / set tags=TAGS;/ " highlight tabs and trailing spaces set listchars=tab:‗‗,trail:‗ set list " f2 runs hasktags map :exec ":!hasktags -x -c --ignore src" " strip trailing whitespace before saving " au BufWritePre *.hs,*.markdown silent! cal StripTrailingWhitespace() " rebuild hasktags after saving au BufWritePost *.hs silent! :exec ":!hasktags -x -c --ignore src" nats-0.1.2/CHANGELOG.markdown0000644000000000000000000000012212216113454013672 0ustar00000000000000000.1 --- * Repository Initialized moving `Numeric.Natural` from `semigroups` 0.8.6 nats-0.1.2/LICENSE0000644000000000000000000000265312216113454011657 0ustar0000000000000000Copyright 2011 Edward Kmett All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. Neither the name of the author nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. nats-0.1.2/nats.cabal0000644000000000000000000000162612216113454012602 0ustar0000000000000000name: nats category: Numeric, Algebra version: 0.1.2 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE author: Edward A. Kmett maintainer: Edward A. Kmett stability: provisional homepage: http://github.com/ekmett/nats/ bug-reports: http://github.com/ekmett/nats/issues copyright: Copyright (C) 2011-2013 Edward A. Kmett synopsis: Haskell 98 natural numbers description: Haskell 98 natural numbers build-type: Simple extra-source-files: .ghci .gitignore .vim.custom .travis.yml README.markdown CHANGELOG.markdown source-repository head type: git location: git://github.com/ekmett/nats.git library hs-source-dirs: src if !impl(hugs) cpp-options: -DLANGUAGE_DeriveDataTypeable build-depends: base >= 2 && < 10 ghc-options: -Wall exposed-modules: Numeric.Natural Numeric.Natural.Internal nats-0.1.2/README.markdown0000644000000000000000000000053612216113454013351 0ustar0000000000000000nats ==== [![Build Status](https://secure.travis-ci.org/ekmett/nats.png?branch=master)](http://travis-ci.org/ekmett/nats) Haskell 98 natural numbers Contact Information ------------------- Contributions and bug reports are welcome! Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net. -Edward Kmett nats-0.1.2/Setup.lhs0000644000000000000000000000016512216113454012456 0ustar0000000000000000#!/usr/bin/runhaskell > module Main (main) where > import Distribution.Simple > main :: IO () > main = defaultMain nats-0.1.2/src/0000755000000000000000000000000012216113454011433 5ustar0000000000000000nats-0.1.2/src/Numeric/0000755000000000000000000000000012216113454013035 5ustar0000000000000000nats-0.1.2/src/Numeric/Natural.hs0000644000000000000000000000102512216113454014775 0ustar0000000000000000----------------------------------------------------------------------------- -- | -- Module : Numeric.Natural -- Copyright : (C) 2011 Edward Kmett, -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett -- Stability : provisional -- Portability : portable -- -- Natural numbers. -- ---------------------------------------------------------------------------- module Numeric.Natural ( Natural , Whole(toNatural) , natural ) where import Numeric.Natural.Internal nats-0.1.2/src/Numeric/Natural/0000755000000000000000000000000012216113454014443 5ustar0000000000000000nats-0.1.2/src/Numeric/Natural/Internal.hs0000644000000000000000000001226512216113454016561 0ustar0000000000000000{-# LANGUAGE CPP #-} #ifdef LANGUAGE_DeriveDataTypeable {-# LANGUAGE DeriveDataTypeable #-} #endif #ifndef MIN_VERSION_base #define MIN_VERSION_base(x,y,z) 1 #endif ----------------------------------------------------------------------------- -- | -- Module : Numeric.Natural.Internal -- Copyright : (C) 2011 Edward Kmett, -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett -- Stability : provisional -- Portability : portable -- -- This module exposes the potentially unsafe operations that are sometimes -- needed for efficiency: The Natural data constructor and unsafePred. -- ---------------------------------------------------------------------------- module Numeric.Natural.Internal ( Natural(..) , Whole(..) , natural ) where import Data.Word import Data.Bits import Data.Ix #ifdef LANGUAGE_DeriveDataTypeable import Data.Typeable #endif newtype Natural = Natural { runNatural :: Integer } deriving ( Eq , Ord , Ix #ifdef LANGUAGE_DeriveDataTypeable , Typeable #endif ) -- | Church decoding natural :: a -> (a -> a) -> Natural -> a natural a _ 0 = a natural a f n = natural (f a) f (unsafePred n) {-# INLINEABLE natural #-} instance Show Natural where showsPrec d (Natural n) = showsPrec d n instance Read Natural where readsPrec d = map (\(n, s) -> (Natural n, s)) . readsPrec d instance Num Natural where Natural n + Natural m = Natural (n + m) {-# INLINE (+) #-} Natural n * Natural m = Natural (n * m) {-# INLINE (*) #-} Natural n - Natural m | result < 0 = error "Natural.(-): negative result" | otherwise = Natural result where result = n - m {-# INLINE (-) #-} abs (Natural n) = Natural n {-# INLINE abs #-} signum (Natural n) = Natural (signum n) {-# INLINE signum #-} fromInteger n | n >= 0 = Natural n | otherwise = error "Natural.fromInteger: negative" {-# INLINE fromInteger #-} instance Bits Natural where Natural n .&. Natural m = Natural (n .&. m) {-# INLINE (.&.) #-} Natural n .|. Natural m = Natural (n .|. m) {-# INLINE (.|.) #-} xor (Natural n) (Natural m) = Natural (xor n m) {-# INLINE xor #-} complement _ = error "Bits.complement: Natural complement undefined" {-# INLINE complement #-} shift (Natural n) = Natural . shift n {-# INLINE shift #-} rotate (Natural n) = Natural . rotate n {-# INLINE rotate #-} bit = Natural . bit {-# INLINE bit #-} setBit (Natural n) = Natural . setBit n {-# INLINE setBit #-} clearBit (Natural n) = Natural . clearBit n {-# INLINE clearBit #-} complementBit (Natural n) = Natural . complementBit n {-# INLINE complementBit #-} testBit = testBit . runNatural {-# INLINE testBit #-} bitSize = bitSize . runNatural {-# INLINE bitSize #-} isSigned _ = False {-# INLINE isSigned #-} shiftL (Natural n) = Natural . shiftL n {-# INLINE shiftL #-} shiftR (Natural n) = Natural . shiftR n {-# INLINE shiftR #-} rotateL (Natural n) = Natural . rotateL n {-# INLINE rotateL #-} rotateR (Natural n) = Natural . rotateR n {-# INLINE rotateR #-} #if MIN_VERSION_base(4,6,0) popCount = popCountDefault {-# INLINE popCount #-} #endif instance Real Natural where toRational (Natural a) = toRational a {-# INLINE toRational #-} instance Enum Natural where pred (Natural 0) = error "Natural.pred: 0" pred (Natural n) = Natural (pred n) {-# INLINE pred #-} succ (Natural n) = Natural (succ n) {-# INLINE succ #-} fromEnum (Natural n) = fromEnum n {-# INLINE fromEnum #-} toEnum n | n < 0 = error "Natural.toEnum: negative" | otherwise = Natural (toEnum n) {-# INLINE toEnum #-} instance Integral Natural where quot (Natural a) (Natural b) = Natural (quot a b) {-# INLINE quot #-} rem (Natural a) (Natural b) = Natural (rem a b) {-# INLINE rem #-} div (Natural a) (Natural b) = Natural (div a b) {-# INLINE div #-} mod (Natural a) (Natural b) = Natural (mod a b) {-# INLINE mod #-} divMod (Natural a) (Natural b) = (Natural q, Natural r) where (q,r) = divMod a b {-# INLINE divMod #-} quotRem (Natural a) (Natural b) = (Natural q, Natural r) where (q,r) = quotRem a b {-# INLINE quotRem #-} toInteger = runNatural {-# INLINE toInteger #-} -- | A refinement of 'Integral' to represent types that do not contain negative numbers. class Integral n => Whole n where toNatural :: n -> Natural unsafePred :: n -> n instance Whole Word where toNatural = Natural . toInteger unsafePred n = n - 1 {-# INLINE toNatural #-} {-# INLINE unsafePred #-} instance Whole Word8 where toNatural = Natural . toInteger unsafePred n = n - 1 {-# INLINE toNatural #-} {-# INLINE unsafePred #-} instance Whole Word16 where toNatural = Natural . toInteger unsafePred n = n - 1 {-# INLINE toNatural #-} {-# INLINE unsafePred #-} instance Whole Word32 where toNatural = Natural . toInteger unsafePred n = n - 1 {-# INLINE toNatural #-} {-# INLINE unsafePred #-} instance Whole Word64 where toNatural = Natural . toInteger unsafePred n = n - 1 {-# INLINE toNatural #-} {-# INLINE unsafePred #-} instance Whole Natural where toNatural = id unsafePred (Natural n) = Natural (n - 1) {-# INLINE toNatural #-} {-# INLINE unsafePred #-}