Sha256: 0ca831c085eea92fcd16676b02a76f310068bd2add5a6c58bc1c58d3605d7963

Contents?: true

Size: 661 Bytes

Versions: 396

Compression:

Stored size: 661 Bytes

Contents

module Octal (showOct, readOct) where

showOct :: Integral a => a -> String
showOct n0 | n0 >= 0   = go (quotRem n0 8) []
           | otherwise = error "only positive numbers supported"
  where
    go (q, r) acc = c `seq` case q of
      0 -> acc'
      n -> go (quotRem n 8) acc'
      where acc' = c : acc
            c = toEnum $ fromEnum '0' + fromIntegral r

readOct :: Integral a => String -> a
readOct = flip go 0
  where
    go []     acc = acc
    go (c:cs) acc | c >= '0' && c <= '8' = acc' `seq` go cs acc'
                  | otherwise = error ("invalid octal digit " ++ show c)
      where acc' = acc * 8 + fromIntegral (fromEnum c - fromEnum '0')

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.158 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.157 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.156 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.155 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.154 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.153 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.152 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.151 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.150 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.149 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.148 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.147 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.146 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.145 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.144 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.143 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.142 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.141 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.140 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs