3 ms·
> But realistically, an unused parameter should probably be removed. Think about the function if-then-else, which you may be familiar with from your favorite l
by the_af 12y ago
> But realistically, an unused parameter should probably be removed.
Think about the function if-then-else, which you may be familiar with from your favorite language :)
if-then-else true branch1 branch2 = branch1
if-then-else false branch1 branch2 = branch2
Obviously you don't want both branches evaluated in any given invocation, and obviously you cannot remove the unused parameter. Note that the purpose is not to "save computation", since for example branch1 may be undefined if cond is false!
When using a language with support for lazy evaluation, you encounter this kind of functions all the time.
- tel 12y agoOf course, in OCaml that's just if_then_else c t e = match c with | true -> t () | false -> e () So the question sort of becomes one of how painful thunking or anonymous function syntax is.