String -> は Proc(A, B).new では表記できない?
3 記事連続で Crystal。
#on の block
の型が String ->
なんだけど、戻り値の型が不明?なので、Proc(A, B).new { |x| ... }
という
Proc
の表記では書けないっぽい………。
こういう風に書きたいけど、エラーになる:
proc = Proc(String, ).new { |x| hoge = x } # エラー!!
C 言語的に考えれば、Void 型にすれば、値を返さない Proc
になるはずだが……:
proc = Proc(String, Void).new { |x| hoge = x } # proc の型は String -> Void になる……
この proc
の型は String -> Void
になる。
Why Crystal People???!!!!!!!!!!!!!!!