クロージャと関数型言語
[id:lethevert:20050811:p3]の続きです。
[id:soutaro:20050812:1123816015]
Cleanで、同じようなことをしてみました。
module closure import StdEnv Start w # lst = [0,1,2,3,4,5,6,7,8,9] # lst2 = map (GetFunc 2) lst # lst3 = map (GetFunc 3) lst # (c, w) = stdio w # c = foldl writeline_l c lst2 # c = fwrites "----\n" c # c = foldl writeline_l c lst3 # (_, w) = fclose c w = w where writeline_l c i # c = fwritei i c # c = fwrites "\n" c = c GetFunc b # c = b = \ x = c*x + 3 /* GetFunc b = afunc where c = b afunc x # d = 3 = c*x + d */ /* GetFunc b = afunc with c = b afunc x # d = 3 = c*x + d */
ラムダ式もwhereブロックやwithブロックも大丈夫ですね。でも、前の記事に載せた、副作用のあるようなタイプは無理だよな。
ところで、クロージャの起源ってLispですかね?