Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] ocaml killer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Issac Trotts <ijtrotts@u...>
Subject: Re: [Caml-list] ocaml and concurrency
On Fri, Jan 30, 2004 at 12:52:42AM -0600, Brian Hurt wrote:
[snip]
> 
> Technically, he's correct.  What C doesn't have is partial function 
> application, which makes having functional types much less worthwhile- 
> it's impossible for a function type to also contain state.  Which is why 
> when I do callbacks in C, I always include a void * context which is 
> passed (uninspected) to the callback routine.
> 
> I mean, writting this function in C would be interesting to say the least:
> 
> let summer ival =
>     let cval = ref ival in
>     let f x = cval := !cval + x; !cval in
>     f
> ;;

OK, maybe C doesn't support it, but it's easy to do this one in C++:

#include <assert.h>

class summer
{
  int cval;
public:
  summer(int ival): cval(ival) {} 
  int operator()(int x) { cval += x; return cval; }
};

int main()
{
  summer s(3);
  assert(s(2)==5);
  assert(s(7)==12);
  return 0;
}

Issac

[snip]

-- 
Issac Trotts
http://redwood.ucdavis.edu/~issac

-------------------
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