Another option, that a lot of haskell code uses if you need to support all
sorts of combinations, is to use record update syntax, so you would do
something along the lines of (trying to mimic patricks syntax):
f(Options { a : 10 with defaultOptions})
where defaultOptions is:
Options { a : 10, b : 10 }
and f is:
fn f(opts : Options) -> int {
...
}
Here the (proposed) syntax doesn't make it as clean as with haskell, where it
would look like:
f(defaultOptions { a : 10})
But it is the same basic idea…. and also isn't particularly verbose (i.e.,
there is not any boiler plate)… in that case though the method chaining seems
better:
f(defaultOptions.a(10))
Though if the record update syntax was lighter weight (it doesn't exist yet,
yes?), it might also be viable.
On Aug 4, 2012, at 2:58 PM, Daniel Patterson wrote:
> Having default parameters seems like overloading, which at least to me, is
> not all that desirable (when avoidable).
>
> Is it that hard to do:
>
> fn f(a : int, b : int) -> int {
> …
> }
> fn f_s(b : int) -> int { f(10, b) }
>
> You get the default param behavior, without the magic of overloading, and it
> is clear from application what you are doing. This costs one line of code,
> and having a separate name for the defaulted version…
>
> On Aug 4, 2012, at 2:28 PM, Patrick Walton wrote:
>
>> On 08/04/2012 11:20 AM, Matthieu Monrocq wrote:
>>> Verbose.
>>>
>>> -- Matthieu
>>
>> Perhaps, but we can write macros for most of this.
>>
>> In general, I'd like to see whether we can avoid adding new features at this
>> stage; the language complexity budget is pretty strained.
>>
>> Patrick
>>
>> _______________________________________________
>> Rust-dev mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/rust-dev
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev