From: Jun Furuse <jun.furuse@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] [ANN] ppx_overload : ppx for user definable SML style overloading
Date: Mon, 13 Oct 2014 21:49:22 +0800 [thread overview]
Message-ID: <CAAoLEWsY8oJZGMEy5CXxQT3FA8iTnO_Ct2SSgbqaJ4CW4fjSuA@mail.gmail.com> (raw)
Hi,
I have OPAM-released ppx_overload, a ppx for user definable SML style
overloading.
For example you can overload (+) and (+.) to Plus.(+) as follows:
module Plus = struct
external (+) : 'a -> 'a -> 'a = "%OVERLOADED"
module Int = struct
let (+) = Pervasives.(+)
end
module Float = struct
let (+) = Pervasives.(+.)
end
end
Then Plus.(+) works for int and float additions!
It works as follows:
* Declaration of overloaded values by external "%OVERLOADED"
* List the instances with the same name in its sub modules.
* The uses of overloaded values are resolved to one of their instances
at typing phase.
The overloading of ppx_overload is pretty limited: you cannot derive
overloading by using overloaded values polymorphicially. You cannot
define overloaded double with the overloaded Plus.(+). But still it is
a very interesting ppx example to combine with the OCaml typing.
ppx_overload is now available in OPAM. More detailed explanation how
it works is explained in the project page:
https://bitbucket.org/camlspotter/compiler-libs-hack . Enjoy!
Thanks
Jun
next reply other threads:[~2014-10-13 13:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-13 13:49 Jun Furuse [this message]
2014-10-13 13:56 ` Peter Zotov
2014-10-13 14:54 ` Alain Frisch
2014-10-14 13:08 ` Jun Furuse
2014-10-14 14:55 ` Peter Zotov
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=CAAoLEWsY8oJZGMEy5CXxQT3FA8iTnO_Ct2SSgbqaJ4CW4fjSuA@mail.gmail.com \
--to=jun.furuse@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).