Created
October 15, 2014 20:02
-
-
Save kyle-ilantzis/5b0cdb071dfc7c70744c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WriteManyInts where | |
import System.IO | |
import Control.Exception(bracket) | |
import qualified Data.Binary as Binary | |
import qualified Data.ByteString.Lazy as ByteString | |
writeManyInts name n | |
| n <= 0 = error "n <= 0" | |
| otherwise = bracket | |
(openBinaryFile name WriteMode) | |
(hClose) | |
(\h -> mapM_ (ByteString.hPut h) $ map Binary.encode ([1..n]::[Int])) | |
-- [1..n] is of type Int to force fixed width encodings. Integer type is variable length. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment