naturals

natural numbers in Haskell
git clone git://git.rr3.xyz/naturals
Log | Files | Refs

Natural.hs (635B)


      1 module Naturals.Natural (
      2     Natural,
      3     ToNatural (..),
      4     FromNatural (..),
      5 ) where
      6 
      7 import Numeric.Natural
      8 
      9 -- | Types supporting conversion to @Natural@.
     10 --
     11 -- If @a@ also implements @FromNatural@, then @toNatural@ and @fromNatural@
     12 -- should be inverses.
     13 class ToNatural a where
     14     toNatural :: a -> Natural
     15 
     16 -- | Types supporting conversion from @Natural@.
     17 --
     18 -- If @a@ also implements @ToNatural@, then @toNatural@ and @fromNatural@
     19 -- should be inverses.
     20 class FromNatural a where
     21     fromNatural :: Natural -> a
     22 
     23 instance ToNatural Natural where
     24     toNatural = id
     25 
     26 instance FromNatural Natural where
     27     fromNatural = id