Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* list composition functions
@ 2000-10-15 23:42 Julian Assange
  2000-10-16  6:57 ` Jacques Garrigue
  2000-10-16  7:58 ` Alain Frisch
  0 siblings, 2 replies; 4+ messages in thread
From: Julian Assange @ 2000-10-15 23:42 UTC (permalink / raw)
  To: caml-list; +Cc: proff


Imagine you have the follow three functions,

let mirror x = [x;x]
let plus1 x = [x+1]
let none x = []

I'm trying to define an operator (>>) that will then operate like so

(mirror >> mirror >> plus1) [1]

[2;2;2;2]

let (>>) a b = function x ->
  let rec loop = function
      [] -> []
    | hd::tl ->
	let rec loop2 = function
	    [] -> loop tl
	  | hd::tl -> b hd @ loop2 tl
	in
	  loop2 (a hd)
  in
    loop x

# (>>);;
- : ('a -> 'b list) -> ('b -> 'c list) -> 'a list -> 'c list = <fun>

While this looks okay, and works fine for two applications, the list
type keeps on growing with each partial application.

plus1 >> plus1 >> plus1 >> plus1;;
- : int list list list -> int list = <fun>
# 

Is there anyway I can prevent this, short of making plus1, etc symmetric
with respect to their argument types?



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

end of thread, other threads:[~2000-10-16 15:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-15 23:42 list composition functions Julian Assange
2000-10-16  6:57 ` Jacques Garrigue
2000-10-16  7:58 ` Alain Frisch
2000-10-16 12:22   ` Julian Assange

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox