From: David Allsopp <dra-news@metastack.com>
To: Mailing List OCaml <caml-list@inria.fr>
Cc: Jordan W <jordojw@gmail.com>
Subject: RE: [Caml-list] Explicit Arity with Polymorphic Variants
Date: Sat, 24 Jan 2015 08:24:02 +0000 [thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9E98923D2@Remus.metastack.local> (raw)
In-Reply-To: <CAPOA5_75KA6DYsYnCT2Ey0hPhbWfosRwzCz4UkPR_Rctc2E8tw@mail.gmail.com>
Jordan W wrote:
> David, are you certain that the explicit_arity attribute is only related to type
> declarations? I do not believe that to be the case. I understand them to apply to
> patterns and expressions as well.
I'm (reasonably) certain that the information it conveys can only ever be useful when you have a type definition.
> (* Declares a variant that accepts a *single* parameter *)
> type oneArgTuple = OneArg of (int*int)
>
> (* Works because arity is massaged into whatever is necessary and doesn't need to be expressed at parse time. *)
> let OneArg (x,y) = OneArg (1,2)
Because of the type definition.
> (* But you can *explicitly* enforce arity and tell the type system that this tuple should be treated as multiple arguments *)
> (* That causes this to fail type checking on this tuple pattern! *)
> let (OneArg (x,y) [@explicit_arity]) = OneArg (1,2);;
> >> Error: The constructor OneArg expects 1 argument(s),
> >> but is applied here to 2 argument(s)
Again, because of the presence of a type definition.
> (* Similarly, at parse time, you can tell the parser to parse an expression as being multiple arguments *)
> let result = OneArg (1,2)[@explicit_arity];;
> >> Error: The constructor OneArg expects 1 argument(s),
> >> but is applied here to 2 argument(s)
>
> So the fact that you can inform the parser to treat a tuple as multiple arguments to a Constructor,
> means that the same should be true of polymorphic variants, but it is not. For example, this type
> checks but it shouldn't:
>
> let (`MyThing (x,y) [@explicit_arity]) = `MyThing (2,2);;
In this context, if the type-checker chose to look at the @explicit_arity attribute, then it must always return a type error when the tuple is neither singleton nor unit (since polymorphic variants only take one argument) - what's the benefit of this, therefore? (I don't quite follow why you'd want to be getting an explicit type check error when using an *internal* OCaml attribute somewhere where it's not intended - http://caml.inria.fr/svn/ocaml/branches/constructors_with_record3/experimental/frisch/extension_points.txt).
David
prev parent reply other threads:[~2015-01-24 8:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-23 6:53 Jordan W
2015-01-23 8:03 ` Jacques Garrigue
2015-01-23 9:04 ` Jordan W
2015-01-23 9:56 ` David Allsopp
2015-01-24 8:52 ` Gabriel Scherer
2015-01-25 8:02 ` Jordan W
2015-01-25 10:11 ` David Allsopp
2015-01-25 19:57 ` Jordo
2015-01-26 4:05 ` Jacques Garrigue
2015-01-24 3:47 ` Jordan W
2015-01-24 8:24 ` David Allsopp [this message]
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=E51C5B015DBD1348A1D85763337FB6D9E98923D2@Remus.metastack.local \
--to=dra-news@metastack.com \
--cc=caml-list@inria.fr \
--cc=jordojw@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