<?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/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?"
  prev="2003/10/08d0b380cf61c19556ca308cbd7a58ed"
  next="2003/10/87502508980ae99e5b009c2f972ffd44"
  prev-in-thread="2003/10/08d0b380cf61c19556ca308cbd7a58ed"
  next-in-thread="2003/10/a1da1088efdb9e488b62d38e41e18696"
  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>
From: Nick Name &lt;nick.name@inwind.it&gt;

&gt; Here it is:
&gt; 
&gt; module type ARROW =
&gt; sig
&gt;   type ('a,'b) t
&gt; 
&gt;   val arr : ('a -&gt; 'b) -&gt; ('a,'b) t
&gt;   val (&gt;&gt;&gt;) : ('a,'b) t -&gt; ('b,'c) t -&gt; ('a,'c) t
&gt;   val (&amp;&amp;&amp;) : ('a,'b) t -&gt; ('a,'c) t -&gt; ('a,('b * 'c)) t
&gt; end

[...]

&gt; (* now in the toplevel
&gt; 
&gt;   # let t = time &gt;&gt;&gt; time;;
&gt;   val t : ('_a, float) Var.Time.t = &lt;abstr&gt; *)
&gt;  
&gt; Well, that '_a is exactly what I wish to avoid;

I see.

&gt; I had this suggestion privately (with simplified type declarations):
&gt; 
&gt; # type ('a,'b) sf = Arr of ('a * float -&gt; 'b);;
&gt; type ('a, 'b) sf = Arr of ('a * float -&gt; 'b)
&gt; # let (&gt;&gt;&gt;) f1 f2  = match f1(),f2() with (Arr f1),(Arr f2) -&gt; Arr (fun 
&gt; (a,s) -&gt; f2 (f1(a,s),s));;
&gt; val ( &gt;&gt;&gt; ) : (unit -&gt; ('a, 'b) sf) -&gt; (unit -&gt; ('b, 'c) sf) -&gt; ('a, 'c) 
&gt; sf =
&gt;   &lt;fun&gt;
&gt; # let time () = Arr (fun (_,t) -&gt; t);;
&gt; val time : unit -&gt; ('a, float) sf = &lt;fun&gt;
&gt; # let t () = time &gt;&gt;&gt; time;;
&gt; val t : unit -&gt; ('a, float) sf = &lt;fun&gt;
&gt; 
&gt; and yet I don't know if it's satisfactory.

What would be the problem?
This is just about delaying the arrow construction, to make sure that
no side-effect may occur.

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

This has nothing to do with decidability at all!
Again, this is the value restriction, which solves a problem with
soundness in presence of side-effects, and this is a FAQ.

And you can perfectly define a polymorphic compose operator.
  # let compose f g x = f (g x);;
  val compose : ('a -&gt; 'b) -&gt; ('c -&gt; 'a) -&gt; 'c -&gt; 'b = &lt;fun&gt;
The only difficulty is that to create polymorphic functions with this
operator you must apply eta-expansion.
  # let swap (x,y) = (y,x);;
  val swap : 'a * 'b -&gt; 'b * 'a = &lt;fun&gt;
  # fun p -&gt; compose swap swap p;;
  - : 'a * 'b -&gt; 'a * 'b = &lt;fun&gt;

By the way, if you are ready to break abstraction (which in your case
doesn't seem essential), you can build a t with the right polymorphic
type:
  # let t = T(fun s -&gt; let T a = time &gt;&gt;&gt; time in a s);;
  val t : ('a, float) Var.Time.t = ...
Not very clean, but you can replace time &gt;&gt;&gt; time by any polymorphic
expression.
It can be made a bit simpler by using a record instead of a sum:
  # let t = {f=fun s -&gt; (time &gt;&gt;&gt; time).f s};;

Jacques Garrigue

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

