Re: [Nomen-dev] Nomen status
Brought to you by:
bhurt
|
From: Brian H. <bh...@sp...> - 2002-11-06 18:56:10
|
On Wed, 6 Nov 2002, Denis wrote:
> Hi Brian
>
> What I don't like --at all-- is that everything is a branch of a tree
> that has tons of ramifications.
> Let's take your example:
>
> let rev_list lst =
> let rec rev_list_int lst accum =
> match lst with
> [] -> accum
> | head :: tail -> rev_list_int tail (head :: accum)
> in
> rev_list_int lst []
> ;;
>
> So here the root is on the first line (let rev_list lst =) --it is even
> probably the '=' sign, but I won't go into details.
> Then you add a branch to declare 'rev_list_int', with its definition.
> Then you finish with the "in" (left branch), which defines the body of
> the function 'rev_list'.
>
> While this structure helps when doing proofs, IMO it's a pain in the
> a*s when you are programming. Some people like it, I don't. I like
> linear, block-based code.
>
> Note that it is certainly possible to adapt the example above to linear,
> block-based programming:
>
> define rev_list(lst)
> {
> define recursive rev_list_int(lst, accum)
> {
> match(lst)
> {
> [] -> return accum;
> head :: tail -> return rev_list_int(tail, head :: accum);
> }
> }
> return rev_list_int(lst, []);
> }
>
> With this programming style, I could make sense of the code without
> banging my head on the walls. It doesn't look that much recursive any
> more (with the "return" statements, it doesn't even looks functional any
> more ;-) ).
>
This is basically what I meant when I talked about eliminating
shift/reduce conflicts.
On the other hand, your example doesn't allow for something that Ocaml
does- currying, which is (as I understand it), creating new functions by
applying some (but not all) arguments to another function (for thos
following along at home, currying is named after Haskell Curry, who
invented lamda calculus).
I could have, for example, written the above example as:
let rev_list = (* note, no argument! *)
let rec rev_list_int accum lst =
match lst with
[] -> accum
| head :: tail -> rev_list_int (head :: accum) tail
in
rev_list_int []
;;
I'm not 100% sure how valuable this feature is. A recent post to the
ocaml list indicates that such currying is 10x as expensive as calling a
function directly. Which makes it a reasonably expensive feature. But
not surprising, since you are in effect creating a function at run time (I
beleive that Ocaml uses gcc's inner functions feature to do this).
Brian
|