Created
June 29, 2014 11:05
-
-
Save freewind/ec1115e56ad2ec64ef10 to your computer and use it in GitHub Desktop.
null
This file contains hidden or 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
| // curry的一个意义是: 方便scala根据第一组参数的内容,推断后面的类型 | |
| // scala采用基于流的局部推断,只会从第一组参数中获取类型信息,再用到其它组参数里 | |
| // 下面只有sort2不用写Int类型 | |
| def sort[T](f: (T,T)=>Boolean)(list:List[T]):List[T] = list | |
| sort[Int]((x,y)=>true)(List(1,2,3)) | |
| def sort2[T](list:List[T])(f: (T,T)=>Boolean):List[T] = list | |
| sort2(List(1,2,3))((x,y)=>true) | |
| def sort3[T](list:List[T], f: (T,T)=>Boolean):List[T] = list | |
| sort3[Int](List(1,2,3), (x,y)=>true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment