From: Jeremy Yallop <yallop@gmail.com>
To: Jiten Pathy <jpathy@fssrv.net>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] phantom type
Date: Mon, 27 Apr 2015 11:36:45 +0100 [thread overview]
Message-ID: <CAAxsn=GiUeB17MWJVaLcu-=2E2kzP3R2cmdHR_BiEPb1Q1gu+g@mail.gmail.com> (raw)
In-Reply-To: <CAL2Z3DBbmv+4e+r7_9Bhbqx2yNhOXHxumxZWc1rGySb6Sr4tug@mail.gmail.com>
On 27 April 2015 at 11:23, Jiten Pathy <jpathy@fssrv.net> wrote:
> Trying to use phantom types instead of gadt for well-constructed term
> example. Is it possible to define an evaluator eval : 'a term -> 'a
> using phantom types?
No, it's not really possible. If the 'a parameter to 'term' is
phantom then 'term' is defined using some other unparameterised type
such as your 'expr':
> type expr = Zero | Succ of expr | Iszero of expr;;
and the problem comes down to writing a function of type
expr -> 'a
which is clearly impossible.
Phantom types only really help with constraints on building or
transforming values, not with deconstructing them.
However, there are various ways of writing well-typed evaluators
without using GADTs, e.g.using a "final" encoding, which represents a
term as an evaluation function:
Finally Tagless, Partially Evaluated:
http://okmij.org/ftp/tagless-final/JFP.pdf
or by encoding GADTs using polymorphism:
First-class modules: hidden power and tantalizing promises
http://okmij.org/ftp/ML/first-class-modules/first-class-modules.pdf
Jeremy.
next prev parent reply other threads:[~2015-04-27 10:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 10:23 Jiten Pathy
2015-04-27 10:36 ` Jeremy Yallop [this message]
2015-04-27 11:32 ` Jiten Pathy
2015-04-27 11:51 ` Stephen Dolan
2015-04-27 12:17 ` Jiten Pathy
2015-04-27 12:30 ` Jeremy Yallop
2015-04-28 4:35 ` Jiten Pathy
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='CAAxsn=GiUeB17MWJVaLcu-=2E2kzP3R2cmdHR_BiEPb1Q1gu+g@mail.gmail.com' \
--to=yallop@gmail.com \
--cc=caml-list@inria.fr \
--cc=jpathy@fssrv.net \
/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