Last active
August 29, 2015 13:56
-
-
Save gregorycollins/9103248 to your computer and use it in GitHub Desktop.
Haskell-cafe thread on Feb 19 2014
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
dist | |
*~ | |
\#* |
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
-- Initial h.cabal generated by cabal init. For further documentation, see | |
-- http://haskell.org/cabal/users-guide/ | |
name: h | |
version: 0.1.0.0 | |
-- synopsis: | |
-- description: | |
-- license: | |
author: Gregory Collins | |
maintainer: [email protected] | |
-- copyright: | |
-- category: | |
build-type: Simple | |
-- extra-source-files: | |
cabal-version: >=1.10 | |
executable h1 | |
main-is: h1.hs | |
ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -O2 -fno-warn-unused-do-bind -rtsopts | |
build-depends: base >=4.5 && <4.6, | |
bytestring | |
default-language: Haskell2010 | |
executable h2 | |
main-is: h2.hs | |
ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -O2 -fno-warn-unused-do-bind -rtsopts | |
build-depends: base >=4.5 && <4.6, | |
bytestring, | |
blaze-builder, | |
io-streams | |
default-language: Haskell2010 | |
executable h3 | |
main-is: h3.hs | |
ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -O2 -fno-warn-unused-do-bind -rtsopts | |
build-depends: base >=4.5 && <4.6, | |
bytestring, | |
blaze-builder, | |
io-streams | |
default-language: Haskell2010 |
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 Main where | |
import qualified Data.ByteString as BS | |
import System.Environment | |
import Data.Word | |
only012 :: Word64 -> Bool | |
only012 0 = True | |
only012 n = (q < 3) && only012 p | |
where (p,q) = n `divMod` 10 | |
go :: Word64 -> IO () | |
go 0 = return () | |
go n = if only012 n | |
then (BS.putStr $ BS.pack ([1] :: [Word8])) >> go (n-1) | |
else (BS.putStr $ BS.pack ([0] :: [Word8])) >> go (n-1) | |
main = do | |
[d] <- map read `fmap` getArgs | |
go d |
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
{-# LANGUAGE BangPatterns #-} | |
module Main where | |
import Blaze.ByteString.Builder as Blaze | |
import Blaze.ByteString.Builder.Internal.Buffer as Blaze | |
import qualified Data.ByteString as BS | |
import System.Environment | |
import qualified System.IO.Streams as Streams | |
import Data.Word | |
only012 :: Word64 -> Bool | |
only012 0 = True | |
only012 n = (q < 3) && only012 p | |
where (!p,!q) = n `divMod` 10 | |
go :: Word64 -> IO () | |
go i = do | |
buf <- Blaze.allocBuffer 4096 | |
os <- Streams.unsafeBuilderStream (return buf) Streams.stdout | |
f os i | |
where | |
f os i = g i | |
where | |
g 0 = return () | |
g n = do | |
let !c = if only012 n then 1 else (0::Word8) | |
Streams.write (Just $! Blaze.fromWord8 c) os | |
g (n-1) | |
main = do | |
[d] <- map read `fmap` getArgs | |
go d |
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
{-# LANGUAGE BangPatterns #-} | |
module Main where | |
import qualified Data.ByteString as BS | |
import System.Environment | |
import Data.Word | |
only012 :: Word64 -> Bool | |
only012 0 = True | |
only012 n = (q < 3) && only012 p | |
where (!p,!q) = n `divMod` 10 | |
go :: Word64 -> IO () | |
go 0 = return () | |
go n = if only012 n | |
then (BS.putStr $ BS.pack ([1] :: [Word8])) >> go (n-1) | |
else (BS.putStr $ BS.pack ([0] :: [Word8])) >> go (n-1) | |
main = do | |
[d] <- map read `fmap` getArgs | |
go d |
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
import Distribution.Simple | |
main = defaultMain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment