Skip to content

Instantly share code, notes, and snippets.

@ojow
Last active August 19, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojow/2c7ec2683ca2c78ca27756740c151a56 to your computer and use it in GitHub Desktop.
Save ojow/2c7ec2683ca2c78ca27756740c151a56 to your computer and use it in GitHub Desktop.
// for a REPL/worksheet session
class Ctx { println("ctx created") }
type Expr = given Ctx => String
case class ExprContainer(e: Expr)
def createContainer(e: Expr) = ExprContainer({ print("."); e})
delegate for Ctx = new Ctx
def anExpr: Expr = { println("expr runs"); "a" }
createContainer(createContainer(createContainer(anExpr).e).e).e
val a: Expr = createContainer(createContainer(createContainer(anExpr).e).e).e
createContainer(a).e
type OldExpr = Ctx => String
case class OldExprContainer(e: OldExpr)
def createOldContainer(e: OldExpr) = OldExprContainer({ print("."); e})
def anOldExpr: OldExpr = { println("expr runs"); _ => "a" }
createOldContainer(createOldContainer(createOldContainer(anOldExpr).e).e).e
val oldA: OldExpr = createOldContainer(createOldContainer(createOldContainer(anOldExpr).e).e).e
createOldContainer(oldA).e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment