I'm trying to create a type
UnaryOrBinaryFunc
, that could conceptually be defined like this:
type A = ArgType => ReturnType
type B = (ArgType, ArgType) => ReturnType
type UnaryOrBinaryFunc = <Some code saying that UnaryOrBinaryFunc is either a A or a B>
in my code I tried to define UnaryOrBinaryFunc
as:
type UnaryOrBinaryFunc = A with B
and it seemed to be acceptable for Eclipse, I sadly didn't find anything
about using the with
keyword in association with the type
keyword on the Internet.
Now if you want a little bit of context on why I want to do that, I wrote something that looks like what I want to accomplish inside my project:
sealed trait Token
case object AND extends Token
case object NOT extends Token
type ArgType
type ReturnType
type A = ArgType => ReturnType
type B = (ArgType, ArgType) => ReturnType
type UnaryOrBinaryFunc = A with B
def f: A = ???
def g: B = ???
Map[TokenType, UnaryOrBinaryFunc] (
NOT -> f,
AND -> g
)
Notice that I used ???
for the definitions of f and g because I didn't want to bother defining them.
Now I get the following error, the same as in my project:
type mismatch; found : TypeDecl.A (which expands to) TypeDecl.ArgType ⇒
TypeDecl.ReturnType required: TypeDecl.UnaryOrBinaryFunc (which expands to)
TypeDecl.ArgType ⇒ TypeDecl.ReturnType with (TypeDecl.ArgType,
TypeDecl.ArgType) ⇒ TypeDecl.ReturnType
I really don't know how to do that, anyone has an idea of how I could define UnaryOrBinaryFunc
so I don't have to modify what is inside my Map
?
Many thanks.