Haskellåå¿è ã®åã試ãããã¨ãã¾ã¨ãã¦ã¿ã
ãªãHaskellã«èå³ããã£ãã®ã
åãHaskellã«èå³ããã£ããã£ããã¯ããã¾ã¤ãã¨ããã²ã ã³ã¼ãã®ä¸ç?ã¹ã¼ãã¼ã»ããã°ã©ãã«ãªã14ã®æèæ³ãï¼é称ããã¹ãæ¬ãï¼ã§ããã
ãã¹ãæ¬ã®ç¬¬14ç« ãé¢æ°åããã°ã©ãã³ã°ã«ã¤ãã¦ãªã©ãã§ã¯ãé¢æ°åããã°ã©ãã³ã°ã®ç¹å¾´ã4ã¤æãããã¦ãã¾ãã
- é¢æ°ãã®ãã®ããã¼ã¿ã¨ãã¦æããï¼ãã¡ã¼ã¹ãã¯ã©ã¹é¢æ°ï¼
- é¢æ°ãå¼æ°ã¨ãã¦åãé«éé¢æ°
- åãå¼æ°ãåãé¢æ°ã¯åãçµæã¨ãªãåç §éææ§
- åç §éææ§ãå®ç¾ããããã®å¯ä½ç¨ã®å¿é¿
ãã®ãã¡ãåç §éææ§ããç¹ã«èå³æ·±ãæãã¾ããããåãå¼æ°ãåãé¢æ°ã¯åãçµæã¨ãªããã®ã§ãããããã£ã¨ãã¹ããæ¸ããããã¯ãã§ãããç¶æ ãã«ãã£ã¦çµæãå¤ãããªãã¸ã§ã¯ãæåè¨èªã§ã¯ãã¹ããæ¸ãã¥ããã¨æ¥é ããæã£ã¦ããã®ã§ããã®åç §éææ§ã¯ç¦é³ã®ããã«æãããã¾ããã
ãã®ãåç §éææ§ãå®ç¾ããããã®å¯ä½ç¨ã®å¿é¿ããå¾¹åºããã¦ããè¨èªãHaskellã§ãã第14ç« ã§ã¯ãHaskellã®ããã°ã©ã ã«ã¯åºæ¬çã«ã¯å¯ä½ç¨ãããã¾ãããã¨æ¸ããã¦ãã¾ããåç« ã§ç´¹ä»ããã¦ããé¢æ°åè¨èªã«ã¯ä»ã«LispãOCamlãErlangãããã¾ãããLispã¨OCamlã«ã¯å¯ä½ç¨ãããã¾ããErlangã¯ä¸¦åè¨ç®ã«ç¹åãã¦ãããããä»ã®åã®èå³ããã¯å¤ãã¾ãã
以ä¸ã®ãããªçç±ã§ãHaskellã«èå³ããã¡ã¾ããã
ã¡ãªã¿ã«ãåããã¾ã¤ãã¨ãããæ¸ãããã総論 複数のプログラミング言語を学ぶ意義 - フリー言語で真のプログラミングを学ぶ:ITproãã§ã¯ãHaskellããä¸çãåºããè¨èªãã¨è©ä¾¡ããã¦ãã¾ãã
GHCãCentOSã«ã¤ã³ã¹ãã¼ã«ããæé
ã¾ãã¯ç°å¢ä½ãã¨ãããã¨ã§ããHowTo:ProgrammingEnvironmentãã«å¾ã£ã¦ãHaskellã®ã³ã³ãã¤ã©ã§ããGHCãæå ã®CentOS5ã«å ¥ãã¦ã¿ã¾ãããæé ã¯ä¸è¨ã®éãã§ãã
$ wget http://haskell.org/ghc/dist/6.12.2/ghc-6.12.2-i386-unknown-linux-n.tar.bz2 $ tar xvf ghc-6.12.2-i386-unknown-linux-n.tar.bz2 $ cd ghc-6.12.2 $ ./configure $ sudo make install
ç¶ãã¦ãããã±ã¼ã¸ç®¡çç¨ã®ã³ãã³ãã§ããcabalãå ¥ãã¾ãããäºåã«gmp-develã¨zlib-develã®ã¤ã³ã¹ãã¼ã«ãå¿ è¦ã§ããã
$ sudo yum install gmp-devel $ sudo yum install zlib-devel $ wget http://hackage.haskell.org/packages/archive/cabal-install/0.8.2/cabal-install-0.8.2.tar.gz $ tar xvf cabal-install-0.8.2.tar.gz $ cd cabal-install-0.8.2 $ sh bootstrap.sh
cabalã®ã¤ã³ã¹ãã¼ã«å¾ãã$HOME/.cabal/binãã«PATHãéãã¾ããã
Haskellããã°ã©ãã³ã°ã®åèã«ããæ¬
ææ³ã®åå¼·ã«ã¯ããµã¤ãã®Haskellããã°ã©ãã³ã° ãµã¤ãã®ããã°ã©ãã®ããã®é¢æ°åè¨èªå ¥éããå½¹ç«ã¡ã¾ããããcatãããheadãã¨ãã£ãUNIXã³ãã³ããHaskellã§æ¨¡ãã¦ã¿ãã¨ããããå§ã¾ããããå æ¥ãUNIXã¨ããèãæ¹âãã®è¨è¨ææ³ã¨å²å¦ããèªãã åã«ã¯ãã£ã¦ã¤ãã®å 容ã§ããã
第9ç« ä»¥éã¯é£ããã£ãã®ã§æµãèªã¿ãã¾ãããå¿ è¦ã«ãªã£ããã¡ããã¨èªããã¨æã£ã¦ãã¾ãã
ãã¤ã¯å ã«ãããã°ã©ãã³ã°Haskellããè²·ããéä¸ã¾ã§èªãã§ããã®ã§ãããæ«æãã¾ãããåã«ã¯é£ããæããããããã§ããããµã¤ããããèªãã ä»ãªããèªããããã«ãªã£ã¦ããããããã¾ããã
åãã¦ã®Haskellããã°ã©ãã³ã°ã®ãé¡
ãããããåãã¦ã®Haskellããã°ã©ãã³ã°ã§ããAmazonã®Product Advertising APIå©ç¨æã«å¿ è¦ãªå¦çãé¡æã«é¸ã³ã¾ããã
Product Advertising APIã®å©ç¨æã«ã¯ããã©ã¡ã¼ã¿æååã¨ç§å¯ãã¼ã§HMAC SHA-256ãè¨ç®ããçµæãbase64ã¨ã³ã³ã¼ãããç½²åãå¿ è¦ã«ãªãã¾ãã詳ããã¯ãアマゾンAPIを使うのに2009年8月15日から認証が必要になるらしいãããåç §ãã ããã
ãã®ããã©ã¡ã¼ã¿æååã¨ç§å¯ãã¼ããå¼æ°ã«åãããHMAC SHA-256ãè¨ç®ããçµæãbase64ã¨ã³ã³ã¼ãããç½²åããè¿ãé¢æ°ããHaskellã§æ¸ãã¦ã¿ããã¨ããéèã§ãããã¹ããã¡ã¼ã¹ããçæ³ãªã®ã§ãããæ©ãæ¸ãããã¦ä»æ¹ããªãã£ãã®ã§ãå®è£ ããå§ãã¾ããã
試è¡é¯èª¤ã®æ«ãã§ããã®ãä¸è¨ã®ã³ã¼ãã§ãï¼ãã¾ã²ã¨ã¤èªä¿¡ãããã¾ãããããããªç¹ã«æ°ã¥ããããããã²ãææãã ããï¼ã
module Main (main) where import System.Environment (getArgs) import Data.ByteString.Lazy.Char8 (pack) import Data.Digest.Pure.SHA (hmacSha256, bytestringDigest) import Data.ByteString.Lazy (unpack) import Codec.Binary.Base64 (encode) main :: IO () main = do args <- getArgs let secret_key = if length args >= 1 then args !! 0 else "" message <- getContents putStrLn $ sign secret_key message sign :: String -> String -> String sign secret_key message = encode $ unpack $ bytestringDigest $ hmacSha256 (pack secret_key) (pack message)
signãç®çã®é¢æ°ã§ããã©ã¤ãã©ãªãå©ç¨ãã¦ããã ãã§ãããé©åãªã©ã¤ãã©ãªãæ¢ãã ãã§ä¸è¦å´ã§ããã
ã¡ããã¨åãã®ï¼
ä¸è¨ã®ã³ã¼ããã³ã³ãã¤ã«ããã«ã¯ãå¿ è¦ãªã©ã¤ãã©ãªãcabalã§ã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããã¾ããæé ã¯ä¸è¨ã®éãã§ããã
$ cabal update $ cabal install dataenc $ cabal install SHA
ã³ã¼ãããsign.hsãã¨ãã¦ä¿åãã³ã³ãã¤ã«ãã¦å®è¡ãã¦ã¿ã¾ãã
$ ghc --make -o sign sign.hs $ echo -n "GET\ > > webservices.amazon.com\ > > /onca/xml\ > > AWSAccessKeyId=00000000000000000000&ItemId=0679722769&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp=2009-01-01T12%3A00%3A00Z&Version=2009-01-06" | ./sign 1234567890 Nace+U3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg=
ãAmazon アソシエイト(アフィリエイト) - ヘルプãã§ç¤ºããã¦ããä¾ã¨åãæååãå¾ãããã®ã§ãè¨ç®çµæã¯åé¡ãªãããã§ãã
ä»å¾ã®äºå®
以ä¸ã§ãææã®ç®çãéæã§ãã¾ãããä»å¾ã¯ä»¥ä¸ã®å 容ã«ææ¦ãããã¨æã£ã¦ãã¾ãã
- HUnitï¼Haskellã®ã¦ããããã¹ããã¬ã¼ã ã¯ã¼ã¯ï¼ã§ãã¹ããå®æ½ãã
- Product Advertising APIç¨ã«ä½¿ããé¢æ°ããã£ã¨æ¸ã
- é¢æ°ãã©ã¤ãã©ãªåãã
- ä»ã®Haskellæ¬ãèªãï¼ãReal World Haskellâå®æ¦ã§å¦ã¶é¢æ°åè¨èªããã°ã©ãã³ã°ããææ¥å±ãäºå®ï¼