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.180 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.179 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.178 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.177 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.176 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.175 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.174 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.173 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.172 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.171 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.170 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.169 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.167 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.166 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.165 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.164 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.163 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.162 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.161 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs
trackler-2.2.1.160 tracks/haskell/exercises/octal/examples/success-standard/src/Octal.hs