From: brogoff@speakeasy.net
To: Christoph Bauer <c_bauer@informatik.uni-kl.de>
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Type inference + optional parameters
Date: Tue, 2 Sep 2003 10:06:51 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.44.0309021003180.23120-100000@grace.speakeasy.net> (raw)
In-Reply-To: <m3ptij88n1.fsf@diebuntekuh.de>
This behavior doesn't seem strange to me, not compared to that function you want
to define, but what the heck, here's one solution to get the type you want
# let do_with_opt_conv ?(conv = Obj.magic) a = conv a;;
val do_with_opt_conv : ?conv:('a -> 'b) -> 'a -> 'b = <fun>
and here's a better one
# let do_with_opt_conv ?(conv = fun x -> invalid_arg "do_with_opt_conv") a = conv a;;
val do_with_opt_conv : ?conv:('a -> 'b) -> 'a -> 'b = <fun>
-- Brian
On Tue, 2 Sep 2003, Christoph Bauer wrote:
> Hi,
>
> ocamls type inference uses information of optionl arguments. This
> results in a strange behaviour. Here is an example:
>
> Objective Caml version 3.07+beta 2
>
> # let do_with_conv ~conv a = conv a;;
> do_with_conv ~conv:int_of_string "1" ;;
> val do_with_conv : conv:('a -> 'b) -> 'a -> 'b = <fun>
>
> This is ok.
>
> # let do_with_opt_conv ?(conv = fun s -> s) a = conv a;;
> do_with_opt_conv ~conv:string_of_int "1";;- : int = 1
> # val do_with_opt_conv : ?conv:('a -> 'a) -> 'a -> 'a = <fun>
> # do_with_opt_conv ~conv:string_of_int "1";;
>
> Is there a solution? It is not possible to
> add the "right" type information:
>
> # let do_with_opt_conv ?(conv : 'a -> 'b = fun s -> s) (a:'a) : 'b = conv a;;
> val do_with_opt_conv : ?conv:('a -> 'a) -> 'a -> 'a = <fun>
>
> Thanks,
> Christoph Bauer
>
> --
> proc self {} {foreach c [split [info body self] ""] d {14 -7 0 0 4 -67 4 73 11
> 69 24 -83 -15 6 -4 -84 78 20 11 -78 -1 -1 79 19 -8 4} { binary scan $c c c
> if {[catch {append r [format %c [expr $c+$d]]}]} {return $r};}};puts [self]
>
> -------------------
> 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
>
-------------------
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-09-02 17:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-02 16:20 Christoph Bauer
2003-09-02 17:06 ` brogoff [this message]
2003-09-03 2:08 ` Jacques Garrigue
2003-09-03 8:08 ` Alain.Frisch
2003-09-06 0:53 ` Jacques Garrigue
2003-09-03 9:56 ` Michal Moskal
[not found] <m3fzjf825m.fsf@diebuntekuh.de>
2003-09-02 19:01 ` brogoff
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=Pine.LNX.4.44.0309021003180.23120-100000@grace.speakeasy.net \
--to=brogoff@speakeasy.net \
--cc=c_bauer@informatik.uni-kl.de \
--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