There are three parts in this type signature:
- Current, original type,
- Return type,
f: (T) => U
Since you're looking at a generic class with a
map method (as opposed to just a stand-alone function), the
T type variable is defined above, in a class type signature:
Try[T]. This explains why there's no
T inside bracket of
map[...]. It's already there, you don't have to specify it again (and you cannot).
Try[T] class signature provides enough context for compiler to know about the source type.
In Haskell, you're dealing with functions, not methods of classes, so you have to state inputs explicitly. There is no
self in Haskell.
In Scala, letters inside brackets
[T] are type variable declarations, whereas in
(T) => U they become actual type signatures. Honestly, in cases like this, I think it would be sufficient to just write
def map(f: (T) => U): Try[U] (note no brackets after
map), but I can't argue with the compiler. You just have to tell the compiler that you're going to use
U in the following type signature.