caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] composing functions...
@ 2005-12-01  0:55 Jonathan Roewen
  2005-12-01  1:34 ` skaller
  2005-12-01  1:38 ` Pietro Abate
  0 siblings, 2 replies; 5+ messages in thread
From: Jonathan Roewen @ 2005-12-01  0:55 UTC (permalink / raw)
  To: caml-list

Hi,

I'm getting a bit stuck, and am wondering if there's anyway to compose
a bunch of functions together easily without having to pre-maturely
apply any of them.

My current idea is trying to use objects, like:

class virtual ['a] composable = object (self)
  method compose a b = self#apply a @ b
  method virtual apply : 'a -> int list
end;;

class c1 = object
  inherit ['a] composable
  method apply (a,b,c) -> [a;b;int_of_char c]
end;;

class c2 = object
  inherit ['a] composable
  method apply a -> [a]
end;;

let o1 = new c1 and o2 = new c2;;

I can do something like let f a1 a2 = o1#compose a1 (o2#compose a2
[]);; and get a list back...

But what I'm wondering is if it's possible to make a generic compose
function that takes say a list of either classes or object instances,
and return a new function that I can apply the bunch of tuples to.

Theory: let f = compose [o1;o2];; f a1 a2;; maybe it's not worth the
hassle (if it's even possible).

Jonathan


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-12-01  8:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-01  0:55 [Caml-list] composing functions Jonathan Roewen
2005-12-01  1:34 ` skaller
2005-12-01  2:00   ` Jonathan Roewen
2005-12-01  8:46   ` Daniel Bünzli
2005-12-01  1:38 ` Pietro Abate

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).