Skip to content

Instantly share code, notes, and snippets.

@cosmo0920
Created March 17, 2012 17:23
Show Gist options
  • Save cosmo0920/2063031 to your computer and use it in GitHub Desktop.
Save cosmo0920/2063031 to your computer and use it in GitHub Desktop.
Haskellでもみっくみく!
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