haskell - Writing lazy curried in scala with multiple parameters -
i'm writing code game exercise learn scala after getting acquainted haskell. started adt follows:
sealed class circle(x: double, y: double, r: double) case class playercircle (x: double, y: double, r: double) extends circle(x, y, r) case class aicircle (x: double, y: double, r: double) extends circle(x, y, r)
i'm trying write lazy, curried val follows (in haskell pseudocode):
addtoplayer :: playercircle -> circle -> playercircle addtoplayer (playercircle px py pr) (aicircle _ _ cr) = playercircle px py (pr + cr) addtoplayer player _ = player
i have following:
def addtoplayer (wcircle : circle) : playercircle = wcircle match { case aicircle (_, _, wr) => copy(this.x, this.y, this.r + wr) case _ => }
what necessary make function curried , lazy?
edit: i've googled answer haven't found article of use please me one.
here's curried function example:
def addtoplayer(c: circle, p: player) = ... actual code... def addtoplayer(c: circle) = p: player => addtoplayer(c, p)
then can this:
val partial = addtoplayer(c) val complete = partial(p)
this lazy because addtoplayer(c, p)
isn't run until both parameters given.
hth.
Comments
Post a Comment