From: Jiten Pathy <jpathy@fssrv.net>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] phantom type
Date: Mon, 27 Apr 2015 03:23:47 -0700 [thread overview]
Message-ID: <CAL2Z3DBbmv+4e+r7_9Bhbqx2yNhOXHxumxZWc1rGySb6Sr4tug@mail.gmail.com> (raw)
Hello,
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? Something like following doesn't work.
type expr = Zero | Succ of expr | Iszero of expr;;
type 'a term = Expr of expr;;
(* ways to construct a term *)
let zero : int term = Expr Zero;;
let succ : int term -> int term = fun (Expr x) -> Expr (Succ x);;
let iszero : int term -> bool term = fun (Expr x) -> Expr (Iszero x);;
let rec eval : 'a.'a term -> 'a = fun (type a) (t : a term) -> match t with
| Expr Zero -> 0
| Expr (Succ e) -> eval (Expr e) + 1
| Expr (Iszero e) -> if (eval (Expr e) == 0) then true else false
;;
next reply other threads:[~2015-04-27 10:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 10:23 Jiten Pathy [this message]
2015-04-27 10:36 ` Jeremy Yallop
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=CAL2Z3DBbmv+4e+r7_9Bhbqx2yNhOXHxumxZWc1rGySb6Sr4tug@mail.gmail.com \
--to=jpathy@fssrv.net \
--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