packages feed

nats (empty) → 0.1

raw patch · 11 files changed

+300/−0 lines, 11 filesdep +basesetup-changed

Dependencies added: base

Files

+ .ghci view
@@ -0,0 +1,1 @@+:set -isrc -idist/build/autogen -optP-include -optPdist/build/autogen/cabal_macros.h
+ .gitignore view
@@ -0,0 +1,13 @@+dist+docs+wiki+TAGS+tags+wip+.DS_Store+.*.swp+.*.swo+*.o+*.hi+*~+*#
+ .travis.yml view
@@ -0,0 +1,8 @@+language: haskell+notifications:+  irc:+    channels:+      - "irc.freenode.org#haskell-lens"+    skip_join: true+    template:+      - "\x0313nats\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}"
+ .vim.custom view
@@ -0,0 +1,31 @@+" 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 <F2> :exec ":!hasktags -x -c --ignore src"<CR><CR>++" 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"
+ CHANGELOG.markdown view
@@ -0,0 +1,3 @@+0.1+---+* Repository Initialized moving `Numeric.Natural` from `semigroups` 0.8.6
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright 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.
+ README.markdown view
@@ -0,0 +1,15 @@+nats+====++[![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
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/runhaskell+> module Main (main) where++> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ nats.cabal view
@@ -0,0 +1,42 @@+name:          nats+category:      Numeric, Algebra+version:       0.1+license:       BSD3+cabal-version: >= 1.10+license-file:  LICENSE+author:        Edward A. Kmett+maintainer:    Edward A. Kmett <ekmett@gmail.com>+stability:     provisional+homepage:      http://github.com/ekmett/nats/+bug-reports:   http://github.com/ekmett/nats/issues+copyright:     Copyright (C) 2011 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+  default-language: Haskell98+  hs-source-dirs: src++  if !impl(hugs)+    other-extensions: DeriveDataTypeable+    cpp-options: -DLANGUAGE_DeriveDataTypeable++  build-depends: base >= 2 && < 10+  ghc-options: -Wall++  exposed-modules:+    Numeric.Natural+    Numeric.Natural.Internal
+ src/Numeric/Natural.hs view
@@ -0,0 +1,19 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.Natural+-- Copyright   :  (C) 2011 Edward Kmett,+-- License     :  BSD-style (see the file LICENSE)+--+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  portable+--+-- Natural numbers.+--+----------------------------------------------------------------------------+module Numeric.Natural+  ( Natural+  , Whole(toNatural)+  ) where++import Numeric.Natural.Internal
+ src/Numeric/Natural/Internal.hs view
@@ -0,0 +1,131 @@+{-# 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 <ekmett@gmail.com>+-- 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(..)+  ) 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+  )++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)+  Natural n * Natural m = Natural (n * m)+  Natural n - Natural m | result < 0 = error "Natural.(-): negative result"+                        | otherwise  = Natural result+    where result = n - m+  abs (Natural n) = Natural n+  signum (Natural n) = Natural (signum n)+  fromInteger n+    | n >= 0 = Natural n+    | otherwise = error "Natural.fromInteger: negative"++instance Bits Natural where+  Natural n .&. Natural m = Natural (n .&. m)+  Natural n .|. Natural m = Natural (n .|. m)+  xor (Natural n) (Natural m) = Natural (xor n m)+  complement _ = error "Bits.complement: Natural complement undefined"+  shift (Natural n) = Natural . shift n+  rotate (Natural n) = Natural . rotate n+  bit = Natural . bit+  setBit (Natural n) = Natural . setBit n+  clearBit (Natural n) = Natural . clearBit n+  complementBit (Natural n) = Natural . complementBit n+  testBit = testBit . runNatural+  bitSize = bitSize . runNatural+  isSigned _ = False+  shiftL (Natural n) = Natural . shiftL n+  shiftR (Natural n) = Natural . shiftR n+  rotateL (Natural n) = Natural . rotateL n+  rotateR (Natural n) = Natural . rotateR n+#if MIN_VERSION_base(4,6,0)+  popCount = popCountDefault+#endif++instance Real Natural where+  toRational (Natural a) = toRational a++instance Enum Natural where+  pred (Natural 0) = error "Natural.pred: 0"+  pred (Natural n) = Natural (pred n)+  succ (Natural n) = Natural (succ n)+  fromEnum (Natural n) = fromEnum n+  toEnum n | n < 0     = error "Natural.toEnum: negative"+           | otherwise = Natural (toEnum n)++instance Integral Natural where+  quot (Natural a) (Natural b) = Natural (quot a b)+  rem (Natural a) (Natural b) = Natural (rem a b)+  div (Natural a) (Natural b) = Natural (div a b)+  mod (Natural a) (Natural b) = Natural (mod a b)+  divMod (Natural a) (Natural b) = (Natural q, Natural r) where (q,r) = divMod a b+  quotRem (Natural a) (Natural b) = (Natural q, Natural r) where (q,r) = quotRem a b+  toInteger = runNatural++-- | 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++instance Whole Word8 where+  toNatural = Natural . toInteger+  unsafePred n = n - 1++instance Whole Word16 where+  toNatural = Natural . toInteger+  unsafePred n = n - 1++instance Whole Word32 where+  toNatural = Natural . toInteger+  unsafePred n = n - 1++instance Whole Word64 where+  toNatural = Natural . toInteger+  unsafePred n = n - 1++instance Whole Natural where+  toNatural = id+  unsafePred (Natural n) = Natural (n - 1)