[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | David J. Trombley <swampy@s...> |
| Subject: | Re: [Caml-list] format4 query |
Right, as I said I can get simple examples to work. But I
can't get syntax such as
# let g (l : listener) (k : int) fmt =
match k with
0 -> 0
| x -> Printf.kprintf l fmt; k;;
val g : listener -> int -> ('a, unit, string, unit)
format4 -> int = <fun>
to function, as you can see the format type has been
inferred to a type that is not useful at all.
I'd like to use kprintf as a side effect to a function which
evaluates to some type, but I would not like that type or
the unit type of a ; evaluation to affect the format type.
-dj
----- Original Message -----
From: "Olivier Andrieu" <andrieu@ijm.jussieu.fr>
To: <swampy@spacebird.net>
Cc: <caml-list@inria.fr>; <hmaon@bumba.net>
Sent: Wednesday, May 19, 2004 3:22 AM
Subject: Re: [Caml-list] format4 query
> David J. Trombley [Wed, 19 May 2004]:
> >
> > Suppose I have
> >
> > type listener = string -> unit
> >
> > which is intended to receive a string type as a value.
> >
> > Could someone demonstrate a function that takes a
listener
> > and a format as arguments, and uses sprintf to obtain a
> > string, and then calls the listener with the string
> > argument?
>
> That is precisely what kprintf does.
>
> # type listener = string -> unit;;
> type listener = string -> unit
> # let f (l : listener) fmt = Printf.kprintf l fmt ;;
> val f : listener -> ('a, unit, string, unit) format4 -> 'a
= <fun>
> # f print_endline "%s %d" "abc" 23 ;;
> abc 23
> - : unit = ()
>
> --
> Olivier
>
-------------------
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