제가 생각했을때는 많은 파라미터들 중에서 논리적으로 구분되는 파라미터끼리
따로 구분을 해주어서 보기 좋은(혹은 이해하기 좋은) 정도의 이점밖에는 모르겠는데
커링을 사용하는 다른 장점은 어떤것이 있나요?
커링은 인자가 여럿인 함수 하나를 인자가 하나인 함수 여럿으로 나누는 기법
입니다. 하스켈 카레(응?) 아저씨가 정리한 수학 이론이라더군요.
암튼 우리가 객체지향에서 객체 추상화를 할 때 변하는 부분과 변하지 않는
부분을 나눠서 상속 구조를 만들듯이 함수 인자의 변하는 부분과 변하지 않는
부분을 나눠 변하지 않는 부분을 미리 전달하고 변하는 부분을 열어두는 함수
추상화 기법이라고 합니다.
스칼라에서는 커링을 쓰면서 (...)를 {..}로 대체할 수 있어서 마치 언어를
확장하는 느낌을 주게 됩니다.
10. 10. 9. 오후 4:38, Outsider 쓴 글:
http://en.wikipedia.org/wiki/Currying
http://ja.wikipedia.org/wiki/%E3%82%AB%E3%83%AA%E3%83%BC%E5%8C%96
일어 위키 자동 번역해서 함 보니 대략 이해가 되는... ^^
http://j2k.naver.com/webtrans.php/korean/ja.wikipedia.org/wiki/%E3%82%AB%E3%83%AA%E3%83%BC%E5%8C%96
HamsterofDeath |
|
HamsterofDeath |
|
Jason Zaugg |
|
HamsterofDeath |
|
Joel Neely |
|
Ingo Maier |
|
imo, it's a disadvantage that you need parameter lists for this
Brian Maso Not actually a bug -- been documented on this list before. Recall that def fun(param1:T1)(param2:T2) = body Is sugar for def fun(param1:T1) = { (param2:T2) => { body } } So if the number and type of the first param list of two functions in the same class are the same, you have ambiguous method overloading. Brian Maso
|
|
On 10/9/10 3:58 PM, Brian Maso wrote: I refuse to recall that :)Not actually a bug -- been documented on this list before. Recall that class A { def f(x: Int)(y: Int) {} def f(x: Int)(s: String) {} } public class A extends java.lang.Object implements scala.ScalaObject{ public void f(int, int); Code: 0: return public void f(int, java.lang.String); Code: 0: return public A(); Code: 0: aload_0 1: invokespecial #21; //Method java/lang/Object."<init>":()V 4: return } You might be referring to eta expansion which happens only at call site, which you can also observe by noticing that class B { def f(x: Int)(y: Int) {} val y = f(1) _ } generates two function classes. As I demonstrated, you can't call any of the f's in class A above, at least not from Scala it seems, and I am wondering why we don't give an error at definition site similar to: scala> class A { | def f(x: Int) {} | def f(x: Int) {} | } <console>:7: error: method f is defined twice def f(x: Int) {} ^ Cheers, Ingo
|
the "usual way" java does it
void/def x(x:T, y:Function[String,T])
the java compiler understands that the second paramter has to be
Function<String, Integer> if the first parameter is an integer. the
scala compiler doesn't
Paul Phillips
On Sat, Oct 09, 2010 at 04:57:41PM +0200, Ingo Maier wrote: It has been opened more than once, and closed wontfix. See the comments> As I demonstrated, you can't call any of the f's in class A above, at > least not from Scala it seems, and I am wondering why we don't give > an error at definition site similar to: > > scala> class A { > | def f(x: Int) {} > | def f(x: Int) {} > | } > <console>:7: error: method f is defined twice > def f(x: Int) {} > ^ in this ticket: https://lampsvn.epfl.ch/trac/scala/ticket/2628 "Ambiguous method overloading compiles, but should not"
|
|
--
Google 그룹스 '한국 스칼라 사용자 모임' 그룹에 가입했으므로 본 메일이 전송되었습니다.
이 그룹에 게시하려면 scala...@googlegroups.com(으)로 이메일을 보내세요.
그룹에서 탈퇴하려면 scala-korea...@googlegroups.com로 이메일을 보내주세요.
더 많은 옵션을 보려면 http://groups.google.com/group/scala-korea?hl=ko에서 그룹을 방문하세요.