caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <lists@philippewang.info>
To: Till Varoquaux <till.varoquaux@gmail.com>, ocaml ml <caml-list@inria.fr>
Subject: Re: [Caml-list] How do I get polymorphic partial application?
Date: Sat, 23 Jun 2007 23:41:00 +0200	[thread overview]
Message-ID: <467D936C.5020501@philippewang.info> (raw)
In-Reply-To: <9d3ec8300706231155p2429504ay6395ea0580756dc7@mail.gmail.com>

Till Varoquaux wrote:
> Humm... I have a small issue here: I need to get the result of the
> partial application of a polymorphic function. Since variable are
> generalized in Let it is generally advised to use eta expansions,
> (i.e transform to a total application).
> sometimes eta expansions just won't do the trick, consider:
>
> let cntTag start=
> let cnt=ref start in
> fun v -> ((incr cnt;!cnt),v)
>
> the partial application is not fully polymorphic
>
> let tag1 = cntTag 1
>
> has type
>
> val tag1 : '_a -> int * '_a = <fun>
>
> the eta expanded equivalent doesn't have the same semantic (it
> actually seems even less useful):
>
> let tag1 x= cntTag 1 x
>
> Is there an elegant solution to that problem?
> Cheers,
> Till
>
Hi,

I think you should not try to "hide" that ugly side effect...

If you do something like

let rec f a = incr x ; a
and x = ref 42          
and start s = x := s ;;

then you don't need to ask yourself how to bypass the type checker...

Still, you can hide things in a module...

module X :
sig 
  val f : 'a -> int * 'a
  val start : int -> unit
end = struct
  let rec f a = incr x ; !x, a
  and x = ref 42    
  and start s = x := s
end
(* include X *)

(only Obj.magic can do exactly what you're asking for -- except the 
"elegant" part)

-- 
Philippe Wang
   mail[at]philippewang.info



  reply	other threads:[~2007-06-23 21:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-23 18:55 Till Varoquaux
2007-06-23 21:41 ` Philippe Wang [this message]
2007-06-23 21:49   ` [Caml-list] " Lukasz Stafiniak
2007-06-23 22:09     ` Till Varoquaux
2007-06-23 22:25       ` Lukasz Stafiniak
2007-06-23 22:11     ` Philippe Wang
2007-06-23 22:28       ` Lukasz Stafiniak
2007-06-23 22:07 ` Zheng Li
2007-06-23 22:09 ` Zheng Li

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=467D936C.5020501@philippewang.info \
    --to=lists@philippewang.info \
    --cc=caml-list@inria.fr \
    --cc=till.varoquaux@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;
as well as URLs for NNTP newsgroup(s).