Haskellçæè¸çããã°ã©ãã³ã°
ãã¡ãã®ã¤ãã³ãã«åå ãã¦ãã¾ãã第0回 スタートHaskell : ATND
è²ã
ããã ãããã§ãææ義ãªæéãããããã¨æã£ã¦ãã¾ãã
ã©ãããããã¨ããããã¾ããï¼
ããã§åºãããããã話ã
æè¸çããã°ã©ãã³ã°
ããããã¨ããã¾ããï¼ãããã¯ç¥ããªãã£ãã
æè¸çããã°ã©ãã³ã°ã§ã¯ããã¥ã¡ã³ãã¨ã½ã¼ã¹ãä½µè¨ããWEBã¨å¼ã°ããã¡ã¿ã½ã¼ã¹ãè¨è¿°ããããããããã¥ã¡ã³ãã¨ã½ã¼ã¹ã³ã¼ããããããçæããããã¨
ã ããã____ãã ãããï¼ãã ã ãï¼¼ ã ï¼ããâã ã âï¼¼ã ï¼ ãã ï¼âï¼ ãï¼âï¼ ï¼¼ãã»ã»ã» |ã ãã ã ï¼__人__ï¼ã ã |ãã /ãããã â©ã âããï¼ (ã ï¼¼ãï¼ ï¼¿ãã|ã | .ï¼¼ãâããï¼ï¼¿ï¼¿|ã | ã ããï¼¼ ï¼ï¼¿ï¼¿ï¼¿ ï¼ ã
ããã¥ã¡ã³ãã¨ã½ã¼ã¹ãåããã¡ã¤ã«ã«æ¸ããããï¼
ä»æ¥å¦ãã ãã¨ããµã¾ãã¦ãé貨ã®ãã¼ã¿æ§é ããã£ã¦ãã¦ããã«æç®ãã¦ããããããã¼ãªãµã³ãã«ã³ã¼ããæè¸çããã°ã©ãã³ã°ã§æ¸ãã¦ã¿ãã
é貨ã®ãã¼ã¿æ§é > data Currency = Dollar Float > | Yen Float > | Euro Float ãã«æç®(ã¬ã¼ãã¯2011/07/24ã®ãã®) > exchangeDollar :: Currency -> Float > exchangeDollar (Dollar a) = a > exchangeDollar (Yen a) = a * 0.01 > exchangeDollar (Euro a) = a * 1.44
Currency.lhs
å®è¡çµæ
*Main> let d = Dollar 100 *Main> exchangeDollar d 100.0 *Main> let y = Yen 100 *Main> exchangeDollar y 1.0 *Main> let e = Euro 100 *Main> exchangeDollar e 144.0
ãã¤ã³ããç®æ¡æ¸ã
ã»ã³ã¡ã³ãããã®ã¾ã¾æ¸ãã¦ãã½ã¼ã¹ã³ã¼ããã³ã¡ã³ãã¢ã¦ããããããªè¦ãç®
ã»æ¡å¼µåã¯.lhsï¼ãã¡ããHaskellã®å ´åï¼
ã»GHCã§æ®éã«ã³ã³ãã¤ã«éã
ã»>ã®å¾ã¯ã¹ãã¼ã¹ãããªãã¨ã³ã³ãã¤ã«ã¨ã©ã¼
ã»ããã¥ã¡ã³ãã¨ã½ã¼ã¹ã¯ï¼è¡ãããªãã¨ã³ã³ãã¤ã«ã¨ã©ã¼
æè¸çããã°ã©ãã³ã°ã£ã¦è¨èèªä½åè³ã§ãå©ç¹ã¨ãæ¬ ç¹ã¨ãæ£ç´ãã¾ããããããã¾ããã
ãã ããããããªã£ã¦æã£ãã®ã§ãç´¹ä»ã
Haskellã«éã£ãããã°ã©ãã³ã°æ¦å¿µã§ã¯ãªãã¨æãã®ã§ãä»ã®è¨èªã«ãããããã