Created
June 10, 2012 09:26
-
-
Save bleis-tift/2904624 to your computer and use it in GitHub Desktop.
JSXでカリーな無名関数書いたら死ねる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 今のJSXだと何書いてるかわからん | |
var adder1 = function(x: int): function(: int): int { | |
return function(y: int): int { return x + y; }; | |
}; | |
// 俺の提案でも->で死ぬるが、 | |
var adder2 = (x: int): (int) -> int -> (y: int): int -> x + y; | |
// 無理してsimple lambda使わなければ、それなりに読める | |
var adder3 = (x: int): (int) -> int -> { | |
return (y: int): int -> x + y; | |
}; | |
// 型推論が入ると仮定する | |
// adder1の場合、最後から2番目の;を忘れそう | |
var adder1 = function(x) { return function(y) { return x + y; }; }; | |
// adder2はまぁ許容範囲か? | |
var adder2 = (x) -> (y) -> x + y; | |
// F#で言うint -> int -> intを受け取る関数を書いてみる | |
// 今のJSXでは戻り値側に関数が来るとうまい読み方が思いつかない | |
function hoge(f: function(: int): function(: int): int): int { | |
return f(10)(20); | |
} | |
// 俺の提案ではカッコがウザいが、読める | |
function piyo(f: (int) -> (int) -> int): int { | |
return f(10)(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment