Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View Fiddlosopher.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
module Main where
 
import qualified Data.ByteString.Char8 as B
import Data.Char (chr,ord)
 
isSpace ∷ CharBool
isSpace ' ' = True
isSpace '\t' = True
isSpace '\n' = True
isSpace '\r' = True
isSpace _ = False
 
toUpper ∷ CharChar
toUpper x
| (x >= 'a' && x <= 'z') = chr $ ord x - 32
| otherwise = x
 
fun ∷ CharCharChar
fun a b | isSpace a = toUpper b
| otherwise = b
 
convert ∷ B.ByteStringB.ByteString
convert = B.tail . B.scanl fun ' '
 
main ∷ IO ()
main = B.readFile "input.txt" >>= B.putStr . convert
View Fiddlosopher.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
module Main where
 
import Data.Char (chr,ord)
import Foreign.C.Types (CInt(..))
import qualified Data.ByteString.Char8 as B
 
foreign import ccall unsafe "u_iswspace"
iswspace ∷ CIntCInt
 
isSpace ∷ CharBool
{-# INLINE isSpace #-}
isSpace c
| c > '\x20' && c < '\xa0' = False
| c == ' ' = True
| '\t' <= c && c <= '\r' = True
| c == '\xa0' = True
| otherwise = iswspace (fromIntegral (ord c)) /= 0
 
toUpper ∷ CharChar
toUpper x
| (x >= 'a' && x <= 'z') = chr $ ord x - 32
| otherwise = x
 
fun ∷ CharCharChar
fun a b | isSpace a = toUpper b
| otherwise = b
 
convert ∷ B.ByteStringB.ByteString
convert = B.tail . B.scanl fun ' '
 
main ∷ IO ()
main = B.readFile "input.txt" >>= B.putStr . convert
View Fiddlosopher.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
module Main where
 
import Data.Char (chr,ord)
import Foreign.C.Types (CInt(..))
import qualified Data.ByteString.Char8 as B
 
foreign import ccall unsafe "u_iswspace"
iswspace ∷ CIntCInt
 
isSpace ∷ CharBool
{-# INLINE isSpace #-}
isSpace c
| c > '\x20' && c < '\xa0' = False
| c == ' ' = True
| '\t' <= c && c <= '\r' = True
| c == '\xa0' = True
| otherwise = iswspace (fromIntegral (ord c)) /= 0
 
toUpper ∷ CharChar
toUpper x
| (x >= 'a' && x <= 'z') = chr $ ord x - 32
| otherwise = x
 
fun ∷ CharCharChar
fun a b | isSpace a = toUpper b
| otherwise = b
 
op ∷ BoolChar → (Bool, Char)
op flag c = if isSpace c then (True,c) else (False,d)
where d = if flag then toUpper c else c
 
main ∷ IO ()
main = B.readFile "input.txt" >>= B.putStr . snd . B.mapAccumL op True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.