分散関数呼び出し
Posted feedbacks - Haskell
Gaucheのコードを見て思いついた。 サーバー側の ghci を ssh で起こす。 自宅のクライアントプログラムからインターネットにあるサーバーへアクセスして pricestring を 10000回実行、結果の文字列10000行をプログラムで受けとる。
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | -- サーバー側 pricestring.hs
import qualified Data.UTF8 as U
import Data.List
pricestring :: Int -> Int -> String
pricestring x y = "販売価格 "++h++" 円 (定価 "++t++" 円から "++r++" %引き)"
where h = comint (x*(100-y) `div` 100)
t = comint x
r = comint y
comint :: Int -> String
comint = reverse . concat . intersperse "," . slice 3 . reverse . show
slice :: Int -> [a] -> [[a]]
slice n = unfoldr phi
where phi [] = Nothing
phi xs = Just $ splitAt n xs
-- クライアント側
module Main (main) where
import Data.List
import Data.Char
import qualified Data.UTF8 as U
import System.IO
import System.Process
remote = "foo.example.org"
main :: IO ()
main = do { (i,o,e,p) <- runInteractiveCommand "ssh "++host++" ghci -v0 pricestring.hs"
; cs <- hGetContents o
; es <- hGetContents e
; hPutStrLn i "U.putStr $ unlines $ map (uncurry pricestring) $ replicate 10000 (2000,20)"
; hFlush i
; hPutStrLn i ":q"
; hFlush i
; putStr cs
; putStr es
}
loop0 h = do { l <- getLine
; if "> " `isSuffixOf` l then return ()
else loop0 h
}
--
{-
*Main> :main
販売価格 1,600 円 (定価 2,000 円から 20 %引き)
販売価格 1,600 円 (定価 2,000 円から 20 %引き)
販売価格 1,600 円 (定価 2,000 円から 20 %引き)
...
... 結果が10000行
...
(1.04 secs, 183701028 bytes)
-}
|


沢渡 みかげ
#3401()
Rating0/0=0.00
[ reply ]