restrict implicit parameter resolution scope

I constantly find I need to write function with inner recursive helper function, and it takes the same parameter list as its outer function, but only an additional accumulator argument:

def encode(tree : Tree, text: String):String = {
    def rec(tree: Tree, text:String, result:String):String = ???

    rec(tree, text, "")

I want to simplify this into :

def encode(tree : Tree, text: String)(implicit result:String = "" ):String

this can remove the inner function definition, but it has a problem of that, see if I need to call a function lookup inside encode, and lookup also takes implicit parameter of type String, the implicit result:String = "" implicitly pass to lookup function.

 def lookup(tree : Tree, text: String)(implicit result:String = "" ):String

I don't want this happen, is there a way to restrict the implicit parameter in lookup from resolving outside of that function? Or other better ideas?


How about using a normal default argument instead and then passing the accumulator explicitly in the implementation:

def encode(tree : Tree, text: String, result : String = "" ): String = {
  encode(new_tree, new_text, new_result)

// call
encode(my_tree, my_text)

Need Your Help

How can I reformat XAML nicely in VS 2008?

.net wpf xaml formatting

Visual Studio 2008's XAML editor (SP1) cannot reformat the XML into a consistent style.

Django Form Submit Button

python django django-forms

I have a pretty simple file upload form class in django:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.