[Haskell-cafe] Idiomatic Haskell equivalent of "keyword
arguments" to functions
dmhouse at gmail.com
Fri Dec 29 17:33:54 EST 2006
On 29/12/06, Paul Moore <p.f.moore at gmail.com> wrote:
> I looked at wxHaskell for inspiration - its approach (button f [text
> := "Quit", on command := close f]) looks quite readable, but slightly
> unusual (to me) for Haskell. It also seems fairly complex to implement
> (ie, my head hurt when I tried to follow the types involved, but maybe
> that's just because it's getting late :-))
This is actually a really nice solution, if you think about it:
1) You don't have to memorise the order the parameters come in (you
can put the parameters in any order in that list).
2) It's self-documenting, f arg1 arg2 arg3 doesn't say what arg1, arg2
and arg3 do, but this way you get an idea.
3) If you had a function in another language with 10 parameters, all
of which are optional, but you want to specify the last one, you have
to include the default values (which may involve looking up what they
are) of the first 9; no such problems here.
Try again to understand the typing, hopefully you'll see this is
probably The Best Way. If you have any questions about the typing
itself, just post them here.
-David House, dmhouse at gmail.com
More information about the Haskell-Cafe