From: "Jørgen Hermanrud Fjeld" <jhf@hex.no>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] function specialization
Date: Tue, 15 Nov 2005 14:00:11 +0100 [thread overview]
Message-ID: <20051115130011.GB8700@hex.no> (raw)
In-Reply-To: <00a701c5e9da$1b0ebc20$670aa8c0@seva>
[-- Attachment #1: Type: text/plain, Size: 1840 bytes --]
From the top of my head, with objects (and classes) you can create
a method that is polymorphic for each invocation "http://caml.inria.fr/pub/docs/manual-ocaml/manual005.html#ss:polymorphic-methods".
For instance:
(**)
class type wrapper = object method wrap : 'a.('a->unit)->'a->unit end;;
let wrapper:wrapper = object
method wrap : 'a.('a->unit)->'a->unit =
fun fn arg -> fn arg
end ;;
let fn1 (v: int) = ()
let fn2 (v: string) = ()
let use = wrapper#wrap fn1 1 ; wrapper#wrap fn2 "" ;;
let use (wrapper:wrapper) = wrapper#wrap fn1 1; wrapper#wrap fn2 "" ;;
use wrapper ;;
(**)
On Tue, Nov 15, 2005 at 02:45:40PM +0300, Vsevolod Fedorov wrote:
> Hello!
>
> I have code like following:
> ----
>
> type 'a wrap = ('a -> unit) -> 'a -> unit
>
> let wrap fn arg =
> fn arg
>
> let fn1 (v: int) = ()
> let fn2 (v: string) = ()
>
> let use (wrap: 'a wrap) =
> wrap fn1 1;
> wrap fn2 ""
> (* ^^^ This expression has type string -> unit but is here used with
> type int -> unit *)
>
> ------
> and get this error from compiler.
> Is there any way to use 'wrap' function for both cases: fn1 and fn2?
> Or is there some 'standard' workarounds/solutions for this problem exists?
>
> Thanks
> Seva
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
--
Sincerely | Homepage:
Jørgen | http://www.hex.no/jhf
| Public GPG key:
| http://www.hex.no/jhf/key.txt
Truly great madness can not be achieved without significant intelligence.
-- Henrik Tikkanen
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2005-11-15 13:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-15 11:45 Vsevolod Fedorov
2005-11-15 12:57 ` [Caml-list] " Alessandro Baretta
2005-11-15 13:00 ` Jørgen Hermanrud Fjeld [this message]
2005-11-15 13:11 ` 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=20051115130011.GB8700@hex.no \
--to=jhf@hex.no \
--cc=caml-list@yquem.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