Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Scala Type Inference

Name: Anonymous 2012-10-27 0:24

Does anyone know the details why?


def map[T, U](a: List[T], f: (T) => U): List[U] =
  for (e <- a) yield f(e)
 
def map0[T, U](a: List[T])(f: (T) => U): List[U] =
  for (e <- a) yield f(e)
 
// type parameter necessary
map(List(1,2,3), (x: Int) => x.toString)
 
// type parameter not necessary
map0(List(1,2,3))(_.toString)

Name: Anonymous 2012-10-27 1:08

it shouldn't be necessary. All these hipster languages want to type inference to be cool but can't quite do it right.


# let rec map__ a f = match a with [] -> [] | x::xs -> f(x)::(map__ xs f);;
val map__ : 'a list -> ('a -> 'b) -> 'b list = <fun>
# map__ [1; 2; 3; 4; 5] ( ( * ) 2);;
- : int list = [2; 4; 6; 8; 10]
# let rec map___ (a,f) = match a with [] -> [] | x::xs -> f(x)::(map___(xs,f));;
val map___ : 'a list * ('a -> 'b) -> 'b list = <fun>
# map___([1; 2; 3; 4; 5], ( ( * ) 2));;
- : int list = [2; 4; 6; 8; 10]

Name: Anonymous 2012-10-27 6:22

Name: sage 2012-10-27 6:28

>>3
All I read was
c BB

$ exit

Name: Anonymous 2012-10-27 7:01

>>2

Ya I just played around with Haskell and Ocaml. They're type inference is on a another level.

Name: Anonymous 2012-10-27 7:03

>>5
They're

What the fuck am I doing

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List