<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/08d0b380cf61c19556ca308cbd7a58ed"
  from="Nick Name &lt;nick.name@i...&gt;"
  author="Nick Name"
  date="2003-10-15T01:48:55"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?"
  prev="2003/10/c1e606f4564d162e20c4d31b0f5e19f4"
  next="2003/10/145c69b15ab7cd8c7ef9cea28a2ee08d"
  prev-in-thread="2003/10/5e8c9bc26aad51865afc7f8b62e1a423"
  next-in-thread="2003/10/145c69b15ab7cd8c7ef9cea28a2ee08d"
  prev-thread="2003/10/a8fa1894bbd369bf8ba65a0a1f44837a"
  next-thread="2003/10/b91f50d10d7d1db0ef09996f1a13d35c"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/b524697dd6429ef4b3d37491d400e8ff"
  from="Nick Name &lt;nick.name@i...&gt;"
  author="Nick Name"
  date="2003-10-13T23:54:30"
  subject="[Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/db9e80867677fab23d16f3aa64fd3fad"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-10-14T01:33:30"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/699b12f0ebe78da74ded3e4cba5c6059"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-10-14T03:03:00"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/9fbf3af3346026a5d782ec2c1884b8e3"
  from="Nick Name &lt;nick.name@i...&gt;"
  author="Nick Name"
  date="2003-10-14T11:21:32"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/5e8c9bc26aad51865afc7f8b62e1a423"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-10-15T00:22:17"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/08d0b380cf61c19556ca308cbd7a58ed"
  from="Nick Name &lt;nick.name@i...&gt;"
  author="Nick Name"
  date="2003-10-15T01:48:55"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/145c69b15ab7cd8c7ef9cea28a2ee08d"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-10-15T02:20:10"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
<msg 
  url="2003/10/a1da1088efdb9e488b62d38e41e18696"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-10-15T11:40:34"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/10/0ffe577457a6e7656e19a496908ae8c2"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-10-14T10:37:40"
  subject="Re: [Caml-list] Is arrow programming impossible in ocaml?">
</msg>
</msg>
</thread>

<contents>
Alle 02:22, mercoledì 15 ottobre 2003, Jacques Garrigue ha scritto:
&gt; I'm afraid you will have to state in more detail what you want to do.
&gt; Or to show some Haskell code.

Here it is:

module type ARROW =
sig
  type ('a,'b) t

  val arr : ('a -&gt; 'b) -&gt; ('a,'b) t
  val (&gt;&gt;&gt;) : ('a,'b) t -&gt; ('b,'c) t -&gt; ('a,'c) t
  val (&amp;&amp;&amp;) : ('a,'b) t -&gt; ('a,'c) t -&gt; ('a,('b * 'c)) t
end

module Time : sig

  include ARROW

  val time : ('a,float) t
  val run : (unit,'a) t -&gt; float -&gt; 'a option
  val const : 'a -&gt; ('b,'a) t
end =
struct
  type state = (float * float)

  (* A signal transformer is a function wich takes the current time (and  
     dt) and maybe returns a value, or stops with None *)

  type ('a,'b) t = T of ((state * 'a) -&gt; (('b * ('a,'b) t) option))

  let rec arr f = T (fun (_,x) -&gt; Some (f x,arr f))

  let rec (&gt;&gt;&gt;) (T a1) (T a2) =
    T (fun (s,x) -&gt;
	 match a1 (s,x) with
	     None -&gt; None
	   | Some (r1,n1) -&gt;
	       match a2 (s,r1) with
		   None -&gt; None
		 | Some (r2,n2) -&gt;
		     Some (r2,n1 &gt;&gt;&gt; n2))

  let rec (&amp;&amp;&amp;) (T a1) (T a2) =
    T (fun arg -&gt;
	 match (a1 arg,a2 arg) with
	     ((None,_)|(_,None)) -&gt; None
	   | (Some (r1,n1),Some (r2,n2)) -&gt; Some ((r1,r2),n1 &amp;&amp;&amp; n2))

  let rec time = T (fun ((t,_),_) -&gt; Some (t,time))

  let run (T f) t = 
    match f ((t,0.0),()) with
	None -&gt; None
      | Some (r,_) -&gt; Some r

  let const x = arr (fun _ -&gt; x) 
end

(* now in the toplevel

  # let t = time &gt;&gt;&gt; time;;
  val t : ('_a, float) Var.Time.t = &lt;abstr&gt; *)
 
Well, that '_a is exactly what I wish to avoid; I had this suggestion 
privately (with simplified type declarations):

# type ('a,'b) sf = Arr of ('a * float -&gt; 'b);;
type ('a, 'b) sf = Arr of ('a * float -&gt; 'b)
# let (&gt;&gt;&gt;) f1 f2  = match f1(),f2() with (Arr f1),(Arr f2) -&gt; Arr (fun 
(a,s) -&gt; f2 (f1(a,s),s));;
val ( &gt;&gt;&gt; ) : (unit -&gt; ('a, 'b) sf) -&gt; (unit -&gt; ('b, 'c) sf) -&gt; ('a, 'c) 
sf =
  &lt;fun&gt;
# let time () = Arr (fun (_,t) -&gt; t);;
val time : unit -&gt; ('a, float) sf = &lt;fun&gt;
# let t () = time &gt;&gt;&gt; time;;
val t : unit -&gt; ('a, float) sf = &lt;fun&gt;


and yet I don't know if it's satisfactory, however I realize that this 
is a general problem with caml view of polymorphism, probably driven by 
type-inference decidability issues; in fact I can't write a polymorphic 
compose operator in general, because I will get exactly the same 
problems.

Vincenzo

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

</contents>

</message>

