From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: nick.name@inwind.it
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Is arrow programming impossible in ocaml?
Date: Wed, 15 Oct 2003 11:20:01 +0900 [thread overview]
Message-ID: <20031015112001U.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <200310150353.46072.nick.name@inwind.it>
From: Nick Name <nick.name@inwind.it>
> Here it is:
>
> module type ARROW =
> sig
> type ('a,'b) t
>
> val arr : ('a -> 'b) -> ('a,'b) t
> val (>>>) : ('a,'b) t -> ('b,'c) t -> ('a,'c) t
> val (&&&) : ('a,'b) t -> ('a,'c) t -> ('a,('b * 'c)) t
> end
[...]
> (* now in the toplevel
>
> # let t = time >>> time;;
> val t : ('_a, float) Var.Time.t = <abstr> *)
>
> Well, that '_a is exactly what I wish to avoid;
I see.
> I had this suggestion privately (with simplified type declarations):
>
> # type ('a,'b) sf = Arr of ('a * float -> 'b);;
> type ('a, 'b) sf = Arr of ('a * float -> 'b)
> # let (>>>) f1 f2 = match f1(),f2() with (Arr f1),(Arr f2) -> Arr (fun
> (a,s) -> f2 (f1(a,s),s));;
> val ( >>> ) : (unit -> ('a, 'b) sf) -> (unit -> ('b, 'c) sf) -> ('a, 'c)
> sf =
> <fun>
> # let time () = Arr (fun (_,t) -> t);;
> val time : unit -> ('a, float) sf = <fun>
> # let t () = time >>> time;;
> val t : unit -> ('a, float) sf = <fun>
>
> 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.
> 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.
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 -> 'b) -> ('c -> 'a) -> 'c -> 'b = <fun>
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 -> 'b * 'a = <fun>
# fun p -> compose swap swap p;;
- : 'a * 'b -> 'a * 'b = <fun>
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 -> let T a = time >>> time in a s);;
val t : ('a, float) Var.Time.t = ...
Not very clean, but you can replace time >>> 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 -> (time >>> 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
next prev parent reply other threads:[~2003-10-15 2:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-13 23:59 Nick Name
2003-10-14 1:33 ` Oleg Trott
2003-10-14 3:02 ` Jacques Garrigue
2003-10-14 11:26 ` Nick Name
2003-10-15 0:22 ` Jacques Garrigue
2003-10-15 1:53 ` Nick Name
2003-10-15 2:20 ` Jacques Garrigue [this message]
2003-10-15 11:39 ` skaller
2003-10-14 10:37 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031015112001U.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=nick.name@inwind.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox