From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Jeff Meister <nanaki@gmail.com>
Cc: Ashish Agarwal <agarwal1975@gmail.com>, Caml List <caml-list@inria.fr>
Subject: AW: [Caml-list] use identity for default function
Date: Thu, 07 Feb 2013 21:04:37 +0100 [thread overview]
Message-ID: <1360267477.18230.9@samsung> (raw)
In-Reply-To: <CAHaHOqRgRkreoKpzs8BG-OSa+g3WQaR_kAAHcYf24QCTbH=vzQ@mail.gmail.com> (from nanaki@gmail.com on Thu Feb 7 20:53:25 2013)
Nope:
# external id : 'a -> 'b = "%identity";;
external id : 'a -> 'b = "%identity"
# (id 5);;
- : 'a = <poly>
# ((id 5) : string);;
Signal -10
# external id : 'a -> 'b = "%identity";;
external id : 'a -> 'b = "%identity"
# let foo ?(f = id) x = f x;;
val foo : ?f:('a -> 'b) -> 'a -> 'b = <fun>
# foo 5;;
- : 'a = <poly>
# ((foo 5):string);;
Signal -10
I think it is not sound what Ashish wants: If f is not passed, the type
checker needs to add a constraint about the return value. This looks
like a dependent type.
Gerd
Am 07.02.2013 20:53:25 schrieb(en) Jeff Meister:
> Can't you simply define it this way? (I don't think I'm using any new
> features, so maybe I misunderstood your question.)
>
> OCaml version 4.00.1
>
> # external id : 'a -> 'b = "%identity";;
> external id : 'a -> 'b = "%identity"
> # let foo ?(f = id) x = f x;;
> val foo : ?f:('a -> 'b) -> 'a -> 'b = <fun>
>
>
> On Thu, Feb 7, 2013 at 11:22 AM, Ashish Agarwal
> <agarwal1975@gmail.com>wrote:
>
> > I'd like to implement
> >
> > val foo : ?f:('a -> 'b) -> 'a -> 'b
> >
> > where the default for f is identity. Is there now a way to do this
> with
> > all the new features of OCaml?
> >
> >
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
------------------------------------------------------------
next prev parent reply other threads:[~2013-02-07 20:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-07 19:22 Ashish Agarwal
2013-02-07 19:53 ` Jeff Meister
2013-02-07 20:04 ` Gerd Stolpmann [this message]
2013-02-07 20:06 ` Gabriel Kerneis
2013-02-09 13:13 ` Goswin von Brederlow
2013-02-09 20:10 ` Jeff Meister
2013-02-07 19:59 ` Martin Jambon
2013-02-07 20:12 ` Gabriel Kerneis
2013-02-07 20:57 ` Ashish Agarwal
2013-02-08 2:47 ` Jacques Garrigue
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=1360267477.18230.9@samsung \
--to=info@gerd-stolpmann.de \
--cc=agarwal1975@gmail.com \
--cc=caml-list@inria.fr \
--cc=nanaki@gmail.com \
/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