0

I recently started working with Functional Programming in Scala and am learning Scala in the process. While attempting one of the Chapter 2 exercises to define a function that curries another function, I ran into this:

If I write

def curry[A,B,C](f: (A,B) => C): A => B => C = a: A => b: B => f(a, b) 

then I get

Chapter2.scala:49: error: ';' expected but ':' found.
a: A => b: B => f(a, b)
_______^
one error found

BUT if I write

def curry[A,B,C](f: (A,B) => C): A => B => C = a => b => f(a, b) 

then it compiles fine, with no warnings, and works. What's the difference?

1
  • 3
    Well the difference is obviously that the first example is not syntactically correct. Commented Aug 23, 2016 at 16:04

1 Answer 1

4

You just need to enclose your variables in parentheses. In your example, you can write:

def curry[A,B,C](f: (A,B) => C): A => B => C = (a: A) => (b: B) => f(a, b) 
Sign up to request clarification or add additional context in comments.

2 Comments

This is a quirk to me; is there an explicit reason why?
In general, parentheses are required in a: A => ... form; they are only allowed to be omitted when it is the last expression in a block. See scala-lang.org/files/archive/spec/2.11/….

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.