File: Naive.hs

package info (click to toggle)
haskell-integer-conversion 0.1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 84 kB
  • sloc: haskell: 294; makefile: 3
file content (20 lines) | stat: -rw-r--r-- 573 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Naive (
    textToInteger,
    byteStringToInteger,
    stringToInteger,
) where

import Data.Char (ord)

import qualified Data.ByteString as BS
import qualified Data.List       as L
import qualified Data.Text       as T

textToInteger :: T.Text -> Integer
textToInteger = T.foldl' (\acc c -> acc * 10 + toInteger (ord c - 48)) 0

byteStringToInteger :: BS.ByteString -> Integer
byteStringToInteger = BS.foldl' (\acc c -> acc * 10 + toInteger c - 48) 0

stringToInteger :: String -> Integer
stringToInteger = L.foldl' (\acc c -> acc * 10 + toInteger (ord c - 48)) 0