http://return0.dyndns.org/log/2009/09/06#s_1 ï¼
æè¿ã¡ãã£ã¨ä»äºãéã㧠...
å°ã£ãããã ãã§ãã¾ã¼ãKuwataããã®æè¿ã®ãã¼ãã¯ã¼ã¯ã®ãããã§ãCatyãWebãã¬ã¼ã ã¯ã¼ã¯ããããªã£ã¦ãã¦ãç°¡åãªãµã³ãã«ãµã¤ããåãåºãã¾ãããã¨ã¯ãããã¾ã ã¾ã ä»æ§ãåºã¾ã£ã¦ãªãã£ãããæ«å®ä»æ§ï¼å®è£ ã§ãè¶ãæ¿ãã¦ããããåé¡ãããã®ã«ããã«ããªãã¦ããã¨ãããããããããã¾ãã
ãµã³ãã«ãµã¤ãã¯ãå½ç¶ã«Catyã¹ã¯ãªããã§å®è£
ãã¦ãã¾ãã
http://d.hatena.ne.jp/m-hiyama/20090810/1249861926 ããï¼
ãæ°åæåã®ã¹ã¯ãªãããã¡ã¤ã«ãæ°åãã§å®ç¾ã§ããåçWebãµã¤ãã§ããç¸å½ã«åºç¯å²ã®è¦æ±ã«å¿ããããã ããã¨è¸ãã§ãã¾ãã
ã¨æ¸ããã®ã§ãçãã¹ã¯ãªããã§åçãµã¤ããåºæ¥ãªãã¨å ¬ç´ãå®ããªãã®ã§ãããããã«ãã¦ããä»ã®ã¹ã¯ãªããã¯ã»ã¨ãã©ãã¯ã³ã©ã¤ãã¼ï¼ä¸è¡ã¹ã¯ãªããï¼ã§ãä½çºçã¨çããããã§ããå æ¥ãCatyã¹ã¯ãªããã¯è¤éãªãã¨ã¯ã§ããªãã®ã§ãããããã«ãã¦ããåç´ãªãã¤ãã©ã¤ã³ããã¯ãã£ã¨è¡¨ç¾åãããã¾ããCatyã¹ã¯ãªããã®åºæ¬ç使ãæ¹ãä¾ã§ç¤ºãã¾ãããã
ã½ããã¦ã§ã¢ãå ¬éãã¦ãªãä»ã®æ®µéã§è§£èª¬ãæ¸ãã¦ããå®æããªãã¦ããã³ãã¤ã§ãããããå¾ã§ã¾ã¨ãã¦æ¸ããã¨ãè² æ ãªã®ã§ãæ¸ãããã¨ã¯æ¸ãã¦ãããã¨ã«ãã¾ããå®ã¯ãå é¨ææ¸ã¨ãã¦æ¸ããã¨ããã®ã§ãããéå ¬éã§æ¸ãæ°ãèµ·ããªãããã¿ãã¿å㯠NND (Non Non-Disclosure) ãªäººã¿ããã
å 容ï¼
- ã³ãã³ãã¨ãã¤ã
- ä¾ã¨ãã¦ä½¿ã2ã¤ã®ã³ãã³ã
- è¤æ°ã®ã³ãã³ãåºåãä¸ç·ã«ãã¦ãã³ãã¬ã¼ãã§å©ç¨ãã
- ã¹ã¯ãªããã§ãã¼ã¿ã®å å·¥
- å°ããã¤ç¢ºèª
- ãããã
ã³ãã³ãã¨ãã¤ã
Catyã®ã³ãã³ãã¯1å ¥åã»1åºåï¼1-in 1-outï¼ã®é¢æ°ã§ããã³ãã³ãfooã®åºåããã³ãã³ãbarã®å ¥åã«æ¸¡ãã«ã¯ãfoo | bar ã¨ãã¤ãè¨å·ã使ãã¾ãã3ã¤ä»¥ä¸ã®ã³ãã³ãããã£ãã¨ãã以ä¸ã®æ¸ãæ¹ã¯æå³çã«ã¾ã£ããç価ã§ãã
- (foo | bar) | baz
- foo | (bar | baz)
- foo | bar | baz
é常ã«éè¦ãªæ³¨æäºé ã¨ãã¦ï¼ ã³ãã³ãå¼æ°ã¯å ¥åã§ã¯ããã¾ãããå¼æ°ã¯ãã³ãã³ãã®åä½ãæ示ããæ å ±ã«ã¯ãªãã¾ãããå ¥åã§ã¯ãªãã®ã§ããã³ãã³ãfooãããfoo 1ãããfoo 2ãããfoo 2 helloãã®ãããªå½¢ã§å¼ã³åºãããã¨ããããã¯ãfoo-1, foo-2, foo-2-hello ã¨ãã3ã¤ã®å¥ã ãªã³ãã³ãã¨èããã»ããããã®ã§ãããããè¤æ°ã®ã³ãã³ããããªã«ãããä¼¼ãåä½ãããããåãç®çã§ä½¿ãããã®ã§ãfooã¨ããååã§ã°ã«ã¼ãã³ã°ããã¨èãã¦ãã ãã*1ã
ã³ãã³ãåã¨æå®ãããå¼æ°ï¼å¼æ°ãªããå«ãã¦ï¼ãã¾ã¨ãã¦ã³ãã³ãå¼ã³åºãã¨å¼ã³ã¾ããã³ãã³ãå¼ã³åºããã¨ã«ãå ¥åã¨åºåã®ä»æ§ã決ã¾ãã¾ããå ¥åºåã®ä»æ§ããããã¡ã¤ã«ã¨å¼ã³ã¾ãã
ä¾ãã°ãgen-ticketã¨ããã³ãã³ãã¯ãå¼æ°ãªãã§ãå ¥åãvoidï¼å ¥åãå¿ è¦ã¨ããªãï¼ãåºåãstringã§ã*2ããã®ãããã¡ã¤ã«ã¯æ¬¡ã®ããã«æ¸ãã¾ãã
- gen-ticket :: void -> string
ã³ãã³ãã®ãããã¡ã¤ã«è¨è¿°ã«ã¯ãã©ããã¦ãåãã©ã¡ã¼ã¿ï¼åå¤æ°ï¼ãå¿ è¦ã«ãªãã¾ããä¾ãã°ããªã«ãããã«å ¥åãåºåã«ã³ãã¼ããã³ãã³ãpass*3ã®ãããã¡ã¤ã«ã¯æ¬¡ã®ããã«ãªãã¾ãã
- pass :: _T -> _T
ã¢ã³ãã¹ã³ã¢ããã¯ãã¾ãååã¯åãã©ã¡ã¼ã¿ã¨ãã¦ä½¿ãã¾ãã
ä¾ã¨ãã¦ä½¿ã2ã¤ã®ã³ãã³ã
todayã¨ããã³ãã³ã*4ã¯ã次ã®ãããªåã®ãã¼ã¿ãè¿ãã¾ãã
object {
"year" : integer,
"month" : integer,
"day" : integer
}
åå®ç¾©å®£è¨ï¼ãJcentricåã·ã¹ãã ã®å®£è¨ã¹ã¿ã¤ã«ã»ã¹ãã¼ãæ§æãåç §ï¼ã¨ã³ãã³ãã®ãããã¡ã¤ã«å®£è¨ãä¸ç·ã«æ¸ãã¨ã次ã®ããã«ãªãã¾ãã
type YMD = object {
"year" : integer,
"month" : integer,
"day" : integer
};command today :: void -> YMD;
ä»ãã°ã¤ã³ãã¦ããã¦ã¼ã¶ã¼ã®æ å ±ããuser-infoã¨ãã³ãã³ãã§åããã¨ãã¾ããã*5
type UserInf = object {
"givenName" : string,
"familyName" : string,
// ãã®ä»ãããã
};command user-info :: void -> UserInfo;
è¤æ°ã®ã³ãã³ãåºåãä¸ç·ã«ãã¦ãã³ãã¬ã¼ãã§å©ç¨ãã
ã³ãã³ãã®åºåããHTMLãã¼ã¸ã«åãè¾¼ãã«ã¯ãã³ãã¬ã¼ãã使ãã¾ããSmarty風æ§æã使ããã¨ã«ãã¦ã次ã®ãã³ãã¬ã¼ããèãã¾ãããã
<p>{$user.familyName}{$user.givenName}ãããããã£ãããã</p> <p>ä»æ¥ã¯{$today.year}å¹´{$today.month}æ{$today.day}æ¥ã§ãã</p>
ãã®ãã³ãã¬ã¼ãã®ä¸ã§ã¯ã$user.familyName, $user.givenName, $today.year, $today.month, $today.day ã¨ãããã³ãã¬ã¼ãå¤æ°ã使ã£ã¦ãã¾ãããã³ãã¬ã¼ãå¤æ°ã®æºæ³ã¨ãªããã¼ã¿ï¼ã³ã³ããã¹ãã¨ãã¦ã次ã®ãããªãã¼ã¿ãæå¾ ãã¦ãããã¨ã«ãªãã¾ãã
type TemplateContext = object {
"user" : object {
"familyName" : string,
"givenName" : string
}
"today" : object {
"year" : integer,
"month" : integer,
"day" : integer
}
};
ãã®ãããªãã¼ã¿ãä½ãã«ã¯ãuser-infoã³ãã³ãã¨todayã³ãã³ããä¸ç·ã«å®è¡ããã°ããã ãã§ããè¤æ°ã³ãã³ããåæã«å®è¡ãã¦*6ãçµæãåä¸JSONãªãã¸ã§ã¯ãã«çµã¿ä¸ããã«ã¯æ¬¡ã®ããã«ãã¾ãã
{
"user" : user-info,
"today" : today
}
ã¿ãã¾ãã¾ã§ããuser-infoããã¯ãfamilyName, givenName以å¤ã®æ å ±ãæ¥ãã§ãããããããã¯ãã³ãã¬ã¼ãã§ã¯ä½¿ãã¾ããï¼åã«æ¨ã¦ããã¾ãï¼ãè¤æ°ã®æ å ±ä¾çµ¦æºããã®ãã¼ã¿ãããã¼ã¸å ã§æ··ãã¦ä½¿ã£ã¦ããã®ã§ãã¼ã«ã«ã»ããã·ã¥ã¢ããã¨è¨ã£ã¦ãããããç¥ãã¾ããã
ãªããã³ã³ããã¹ãã®ãã¼ã¿åå®ç¾©ã¨ãã³ãã¬ã¼ããä¸ããããã°ããã®æ´åæ§ã¯ãJSONãã¼ã¿ã«ã¢ã¯ã»ã¹ãããã¹å¼ã®æ£ããã«ã¤ãã¦ãã§è¿°ã¹ãæ¹æ³ã§æ¤è¨¼ã§ãã¾ãã
ã¹ã¯ãªããã§ãã¼ã¿ã®å å·¥
次ã«ãå°ãéã£ããã³ãã¬ã¼ããèãã¾ãã
<p>{$userName}ãããããã£ãããã</p> <p>ä»æ¥ã¯{$today.year}å¹´{$today.month}æ{$today.day}æ¥ã§ãã</p>
ä»åº¦ã¯ãã³ã³ããã¹ãã¨ãã¦æ¬¡ã®ãããªãã¼ã¿ãæå¾ ãã¦ãããã¨ã«ãªãã¾ãã
type TemplateContext = object {
"userName" : string,
"today" : object {
"year" : integer,
"month" : integer,
"day" : integer
}
};
ç·´ç¿ã¨ãã¦ãuser-infoã®åºåãã¹ã¯ãªããå ã§å å·¥ãã¦ã¿ã¾ããããã¯ãããã¾ã§ç·´ç¿åé¡ã§ããå®éã«ã¯ããã³ãã¬ã¼ãå´ã§ç°¡åã«ã§ãããã¨ããã¹ã¯ãªããã§è¡ããã¨ã¯ã奨ããã¾ããã
ãã¦ãuser-infoã³ãã³ãã®åºåãããã³ãã¬ã¼ããæå¾ ãã¦ããå½¢ã«å å·¥ããã«ã¯ã次ã®Catyã¹ã¯ãªããã使ãã¾ãã
{
"userName" : (user-info | [getpv familyName, getpv givenName] | concat),
"today" : today
}
ã¯ããã¦è¦ãã¨ãªãã¸ãã¤ã«è¦ãã¾ããã説æãã¾ããããåé¡ã¯ã次ã®ãã¤ãã©ã¤ã³ã§ãã
- (user-info | [getpv familyName, getpv givenName] | concat)
ãã¤ãã©ã¤ã³ã¯å·¦ããå³ã¸ã¨æµããã®ã§ãå·¦ããé ã«ä½ãèµ·ããããè¦ã¦ããã¾ããã¾ããuser-infoã®åºåã次ã®ããã§ãã£ãã¨ãã¾ãããã
{
"givenName" : "ãã³å",
"familyName" : "æ¿æ±",
// ãã®ä»ãããã
}
getpv ï¼ããããã£åï¼ ã¯ãJSONãªãã¸ã§ã¯ãããç¹å®ããããã£ã®å¤ãåãåºãã³ãã³ãï¼get property valueï¼ã§ãããã£ã¦ããã¤ãã©ã¤ã³ user-info | getpv familyName ã¯ãæåå "æ¿æ±" ãåºåãã¾ããé åå½¢å¼ã«ä¸¦ã¹ãããè¤æ°ã®ã³ãã³ãã«ã¯ãåãå ¥åãä¸ãããã¦ãå®è¡çµæã§ããåºåãé åãã¼ã¿ã«ç·¨æããã¾ãã
ãã®ãã¨ããã[getpv familyName, getpv givenName] ã®åºåãé åãã¼ã¿ ["æ¿æ±", "ãã³å"] ã§ãããã¨ãåããã¾ããconcat ã¯æååãªã¹ãå ã®æåå群ãé£çµï¼é£æ¥ï¼ããã³ãã³ãã§ãã
å°ããã¤ç¢ºèª
Catyã®ããã¨ããã¯ã対話çã·ã§ã«ï¼ã³ãã³ãããã³ããï¼ãããã®ã§ãã³ãã³ãã®åãæ¹ãå°åãã«ãã¦ããã®å ´ã§ç¢ºèªã§ãããã¨ã§ãã次ã®ãããªã³ãã³ãã©ã¤ã³ãå®è¡ãã¦ãã³ãã³ãã®åºåãç®ã§ç¢ºèªã§ãã¾ãã
- user-info
- user-info | getpv familyName
- user-info | getpv givenName
- user-info | [getpv familyName, getpv givenName]
- ["æ¿æ±", "ãã³å"] | concat
user-infoã®åºåãç´æ¥ä½¿ãå¤ããã«ãtest-user.json ã¨ãããã¡ã¤ã«ã«ãã¼ã¿ãæ¸ãã¦ãããªãã
- read test-user.json | [getpv familyName, getpv givenName]
ã®ãããªæ¹æ³ã§ããã¹ãã§ãã¾ã*7ã
ãããã
Catyã¹ã¯ãªããã®å¯ä¸ã®å¶å¾¡æ§é ã¯å¤æ¹åæ¡ä»¶åå²ã§ããä»»æã®æ¡ä»¶å¼ã使ããããã§ã¯ãªãã¦ãã¿ã°ã¨ããç®å°ã«å¾ã£ã¦å ´ååããããã ãã§ãã貧弱ãããå°è±¡ãããã¾ããããã®å°è±¡ããã¯å¼·åãªå¶å¾¡æ§é ã¨ãªãå¾ã¾ãã次ã®æ©ä¼ã«ããã®å¶å¾¡æ§é ãç´¹ä»ãã¾ãã
*1:ã³ãã³ãã®åè«çã»ãã³ãã£ã¯ã¹ã¯ãindexed family of morphisms ã§ãã
*2:ã¾ã æªå®è£ ã§ãããã¯ã³ã¿ã¤ã ãã±ããï¼ãã¼ã¯ã³ï¼ãçæããã³ãã³ãã§ãã
*3:å°ãåã¾ã§ããã®ã³ãã³ãã¯catã¨ããååã«ããã¤ããã§ãããããæ´å²çäºæ ãç¥ããªãã¨æå³ä¸æãªååãªã®ã§ãæªããä¼çµ±ã«å¾ãã®ã¯æ¢ãããã¨ã«ãã¾ããã
*4:ç¾ç¶ããªããnowã¨ããååã«ãªã£ã¦ãã¾ãã
*5:ã¦ã¼ã¶ã¼æ å ±ã¯ãCatyå ã®ç°å¢å¤æ°ããåãã¾ãããã³ãã³ãä»æ§ã¯ã¾ã åºã¾ã£ã¦ã¾ããï¼å®è£ ã¯ç°¡åã§ãããï¼ã
*6:ç¾å¨ã®å®è£ ã¯é 次å®è¡ã§ããããããæ¦å¿µçã«ã¯ä¸¦åå®è¡ã¨èãã¾ãã
*7:readã¯ãã¡ã¤ã«ããèªãã ãã¼ã¿ãåºåã«æµãã³ãã³ãã§ããããã«ã¯catã¨ããå¥åãä»ãã¦ãããããããã¾ããã