Created
March 17, 2012 17:23
-
-
Save cosmo0920/2063031 to your computer and use it in GitHub Desktop.
Haskellでもみっくみく!
This file contains hidden or 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 Network | |
import System.IO | |
import System.Exit | |
import Control.Exception | |
import Prelude hiding (catch) | |
sendMessage :: String -> IO () | |
sendMessage msg = withSocketsDo $ do | |
hSetBuffering stdout NoBuffering | |
h <- connectTo "127.0.0.1" (PortNumber 3939) | |
hSetEncoding h utf8 | |
hSetBuffering h LineBuffering | |
hPutStrLn h msg | |
catch (hGetLine h) | |
(\e -> return (e::SomeException) >> return "send done.") | |
>>= putStrLn | |
hClose h | |
checkLengthAndTwit msg | |
| 140 < length msg = putStrLn "over 140 characters!!" | |
| otherwise = sendMessage msg | |
main = do putStrLn "Input Tweet" | |
msg <- getLine | |
checkLengthAndTwit msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment