A way to make long def signatures more pleasant?

This is going to look like Haskell. That is hovewer not at all the goal of this. I’m finding it relatively difficult to follow more involved or just long Scala signatures. So, with this in mind…

def myFunc[A, B, C, D, E](a : A, b : B)(c : C)(given d : D): E = ???

could look like this:

[A, B, C, D, E] => (A, B) => (C) => (given D) => E def myFunc(a, b)(c)(d) = ???

with the intent of course of enabling

[A, B, C, D, E] => (A, B) => (C) => (given D) => E 
def myFunc(a, b)(c)(d) = ???

the fact that methods have access to this could optinally be reflected in the type sgnature or omitted like above.

It could work for extension methods too, where

def [A,B](ma : Maybe[A]) map(func : A => B) : Maybe[B] = ???

could just beecome

[A, B] => Maybe[A] => (A => B) => Maybe[B]
def (ma) map (func) = ???

although there is an ambiguity wrt. when is there an omitted signature part representing this (maybe not a good idea to have it there optionally)

I’d find this much more readable, thought I’d ask what you think. Im sure there are some problems with it, but it could be an okay-ish starting point to a discussion eventually adding value to Scala.

Honestly, that looks longer and somewhat more complicated, not to mention that it would probably be harder to parse. I do agree that long method signatures can get very confusing, however, but usually documentation and good formatting is enough to help with that.


You can already get pretty close to this, by breaking up the signature across multiple lines. It’s surprisingly flexible:

def oneline[A, B, C, D, E](a : A, b : B)(c : C)(using d : D): E = ???

def hanging[A, B, C, D, E](a : A, b : B)
                          (c : C)
                          (using d : D): E = ???

def oneLineEach
    [A, B, C, D, E]
    (a : A, b : B)
    (c : C)
    (using d : D)
    : E = ???

def forTheReallyComplexSignatures
      a : A, 
      b : B
    (c : C)
    (using d : D)
    : E = ???