æ¨æ¥ã®ãzipãèªç¶å¤æã ã¨ãã話ãã«ããã¦ãzipã®èªç¶æ§ã¯æ¬¡ã®å¯æå³å¼ã§è¡¨ç¾ã§ããã¨è¿°ã¹ã¾ããã
PLL(A, B) - zip_(A,B) â LP(A, B) ï½ ï½ PLL(f, g) LP(f, g) â â PLL(C, D) - zip_(C,D) â LP(C, D)
ããã§ãPLLã¨LPã¯ãCÃCâC ã¨ããé¢æã§ããA, B, C, D ã¯åCã®ãã¹ã¦ã®å¯¾è±¡ã«æ¸¡ã£ã¦åããã¨ã«ãªãã¾ããã¾ããf:AâCãg:BâD ãããããå°ã«å¯¾ãã¦å¤åããã¾ããå ¨ç§°è¨å·ã使ã£ãè«çå¼ã§æ¸ããªãï¼
- âA, B, C, Dâ|C|.âfâC(A, C), gâC(B, D). PLL(f, g);zipC,D = zipA,B;LP(f, g)
ã§ããååã®çå¼ h = k ã¯ãâzâZ. h(z) = k(z) ã®å½¢ãªã®ã§ããããå±éããã¨ï¼
- âA, B, C, Dâ|C|.âfâC(A, C), gâC(B, D).âzâPLL(A, B). zipC,D(PLL(f, g)(z)) = LP(f, g)(zipA,B(z))
ã¨ã©ã¤ãã¨å ¨ç§°è¨å·ãç¶ããè«çå¼ã«ãªãã¾ããããã¹ã¦ã®â¦ã®ãã¹ã¦ã®â¦ã®ãã¹ã¦ã®â¦ã®ãã¨ãã£ãæå³ãªã®ã§ã1åã2åã®äºä¾ã«ã¤ãã¦ç¢ºèªãã¦ãä½ã®æå³ãããã¾ãããã¨ã¯ããã1åã2åã®äºä¾ã§ã確èªãã¦ã¿ãããã®ã§ãã
CatyScriptã¯æ示çãªåä»ããæ¸ãã®ãå²ã¨å¾æãªã®ã§ãå®å ¨ã«åä»ãããzipãæ¸ãã¦ããããèªç¶å¤æã§ãããã¨ã zip-is-natural ã¨ããè¿°èªã§è¡¨ç¾ãã¾ãã
/** ãã¹ããµã³ãã« */ command test-sample :: void -> Logical { [ [true, false, false, true], [4, 5, 6, 7] ] | zip-is-natural"to-string" "num:inc" };
ãã®äºä¾ã§ã¯ã4ã¤ã®å¯¾è±¡A, B, C, Dã«ã¯æ¬¡ã®ããã«åï¼éåï¼ãä»£å ¥ããã¾ãã
- A = boolean, B = integer, C = string, D = number
f:AâC 㯠to-string : booleanâstringãg:BâD ã¨ãã¦ã¯ num:inc : integerânumberï¼æ°ã«1ã足ãï¼ã使ãã¾ããå®éã«è©¦ããã¼ã¿ã¯ãPLL(boolean, string) ã®è¦ç´ ã§ãã [ [true, false, false, true], [4, 5, 6, 7] ] ã§ãã
caty:test> test-sample @True [ [ [ "true", 5 ], [ "false", 6 ], [ "false", 7 ], [ "true", 8 ] ], [ [ "true", 5 ], [ "false", 6 ], [ "false", 7 ], [ "true", 8 ] ] ]
èªç¶å¤æã¨ãã¦ã®zipã®å®ç¾©ã¯ãã®ä¸ã«ããã¾ãã
/** å°ãå¼æ°ã«ããããã®ãã³ãã£ããå®ç¾© */ type Code<X, Y> = string(remark="X -> Y ã®ã³ã¼ãã表ãæåå"); /** ãªã¹ãé¢æ */ type List<A default any> = [A*]; class List = { command fmap<A default any, B default any> [Code<A, B> code] :: List<A> -> List<B> { each {[pass, %1] | eval} }; }; /* ãã¢ãªã³ã°é¢æ */ type Pair<A default any, B default any> = [A, B]; class Pair = { command fmap<A default any, B default any, C default any, D default any> [Code<A, C> code1, Code<B, D> code2] :: Pair<A, B> ->Pair<C, D> { =[ [pass, %1] | eval, [pass, %2] | eval, ] }; }; /* PLL = Pair(List(-), List(-)) é¢æ */ type PLL<A default any, B default any> = Pair<List<A>, List<B>>; class PLL = { command fmap<A default any, B default any, C default any, D default any> [Code<A, C> code1, Code<B, D> code2] :: PLL<A, B> ->PLL<C, D> { =[ each {[pass, %1] | eval}, each {[pass, %2] | eval}, ] }; }; /* LP = List(Pair(-, -)) é¢æ */ type LP<A default any, B default any> = List<Pair<A, B>>; class LP = { command fmap<A default any, B default any, C default any, D default any> [Code<A, C> code1, Code<B, D> code2] :: LP<A, B> ->LP<C, D> { each { =[ [pass, %1] | eval, [pass, %2] | eval, ] } }; }; /** èªç¶å¤æã¨ãã¦ã®zip */ command zip<A default any, B default any> :: PLL<A, B> -> LP<A, B> { list:zip }; /** zipã®èªç¶æ§ */ command zip-is-natural<A default any, B default any, C default any, D default any> [Code<A, C> code1, Code<B, D> code2] :: PLL<A, B> -> Logical { [ PLL.fmap<A, B, C, D> %1 %2 | zip<C, D> , zip<A, B> | LP.fmap<A, B, C, D> %1 %2 , ] | eq }; /** ãã¹ããµã³ãã« */ command test-sample :: void -> Logical { [ [true, false, false, true], [4, 5, 6, 7] ] | zip-is-natural<boolean, integer, string, number> "to-string" "num:inc" };