From: "chris.danx" <chris.danx@ntlworld.com>
To: Brian Hurt <bhurt@spnz.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Closure & Ref
Date: Mon, 17 Nov 2003 21:35:10 +0000 [thread overview]
Message-ID: <3FB93F0E.2070501@ntlworld.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0311171522360.5009-100000@localhost.localdomain>
Brian Hurt wrote:
> Since you're not setting the reference, why have one? Instead, try:
>
> let prodAdd x = fun y -> x + y
>
> But we can do it simpler than that:
>
> let prodAdd x y = x + y
>
> And use partial function application. (prodAdd 4) returns a function
> which adds 4 to whatever int parameter passed to it.
I didn't know OCaml had partial function application, thanks! I have
programmed in Haskell before, but never got seriously into it (the
things I wanted to do like IO where "advanced" in Haskell, whereas
they're basic to me. That's one reason I want to learn OCaml, it
doesn't so hard to do trivial interaction).
> This allows you to have multiple different lists being constructed
> independently. Note, the above code is actually more generic than it
> looks- I had to add an explicit type statement to make it "come out
> correct". Without the explicit type information:
>
> let make_listacc () =
> let r = ref [] in
> let acc x = r := x :: !r
> and lst () = !r
> in acc, lst
> ;;
>
> The function is both clearer than the original, and creates lists of any
> type, not just ints. If you hear me bitching about C++ and Java making
> generics "special and extraordinary", this is a classic example of what
> I'm kvetching about.
I hear you. From my previous spell in FP I really got to like the ease
of "generics" which are inconvient in C++ and a pain in Ada. GUIs and
IO was just easier.
[snip]
> If you want to access specific members of a list (other than the head), I
> wouldn't recommend using a list, but instead some other datastructure (an
> array or hash table being the obvious choices).
It was just a toy example to see if I could get that aspect of this idea
to work in OCaml. Hmm...
Thanks!
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
prev parent reply other threads:[~2003-11-17 21:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-17 19:37 chris.danx
2003-11-17 21:02 ` Dustin Sallings
2003-11-17 21:48 ` Dustin Sallings
2003-11-17 21:43 ` Brian Hurt
2003-11-17 21:35 ` chris.danx [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3FB93F0E.2070501@ntlworld.com \
--to=chris.danx@ntlworld.com \
--cc=bhurt@spnz.org \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox