From: Nick Name <nick.name@inwind.it>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Is arrow programming impossible in ocaml?
Date: Wed, 15 Oct 2003 03:53:45 +0200 [thread overview]
Message-ID: <200310150353.46072.nick.name@inwind.it> (raw)
In-Reply-To: <20031015092206F.garrigue@kurims.kyoto-u.ac.jp>
Alle 02:22, mercoledì 15 ottobre 2003, Jacques Garrigue ha scritto:
> I'm afraid you will have to state in more detail what you want to do.
> Or to show some Haskell code.
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
module Time : sig
include ARROW
val time : ('a,float) t
val run : (unit,'a) t -> float -> 'a option
val const : 'a -> ('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) -> (('b * ('a,'b) t) option))
let rec arr f = T (fun (_,x) -> Some (f x,arr f))
let rec (>>>) (T a1) (T a2) =
T (fun (s,x) ->
match a1 (s,x) with
None -> None
| Some (r1,n1) ->
match a2 (s,r1) with
None -> None
| Some (r2,n2) ->
Some (r2,n1 >>> n2))
let rec (&&&) (T a1) (T a2) =
T (fun arg ->
match (a1 arg,a2 arg) with
((None,_)|(_,None)) -> None
| (Some (r1,n1),Some (r2,n2)) -> Some ((r1,r2),n1 &&& n2))
let rec time = T (fun ((t,_),_) -> Some (t,time))
let run (T f) t =
match f ((t,0.0),()) with
None -> None
| Some (r,_) -> Some r
let const x = arr (fun _ -> x)
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 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, 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
next prev parent reply other threads:[~2003-10-15 1:48 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 [this message]
2003-10-15 2:20 ` Jacques Garrigue
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=200310150353.46072.nick.name@inwind.it \
--to=nick.name@inwind.it \
--cc=caml-list@inria.fr \
/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