* [Caml-list] beginner question about pattern matching @ 2017-10-19 13:38 Matej Košík 2017-10-19 14:16 ` vrotaru.md 2017-10-19 14:34 ` Gabriel Scherer 0 siblings, 2 replies; 9+ messages in thread From: Matej Košík @ 2017-10-19 13:38 UTC (permalink / raw) To: caml-list [-- Attachment #1.1: Type: text/plain, Size: 683 bytes --] Hi, I am trying to do simple pattern matching of these values: https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 What I would like to do is: | [Rtag the_whole_4_tuple] -> the_whole_4_tuple However, when I try to do that, I am getting: Error: The constructor Rtag expects 4 argument(s), but is applied here to 1 argument(s) This: | [Rtag (f1,f2,f3,f4)] -> f1,f2,f3,f4 of course works but (regardless of the chosen bound variable names), it looks amateurish. What's the right way to do this? (I would like just to bind a 4-tuple and then return it) (Apologies in advance for a stupid question.) [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 13:38 [Caml-list] beginner question about pattern matching Matej Košík @ 2017-10-19 14:16 ` vrotaru.md 2017-10-19 14:24 ` Matej Košík 2017-10-19 14:34 ` Gabriel Scherer 1 sibling, 1 reply; 9+ messages in thread From: vrotaru.md @ 2017-10-19 14:16 UTC (permalink / raw) To: Matej Košík; +Cc: caml-list [-- Attachment #1: Type: text/plain, Size: 844 bytes --] [ Rtag (_,_,_,_) as rtag] -> rtag On Thu, Oct 19, 2017, 16:39 Matej Košík <mail@matej-kosik.net> wrote: > Hi, > > I am trying to do simple pattern matching of these values: > https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 > > What I would like to do is: > > | [Rtag the_whole_4_tuple] -> > the_whole_4_tuple > > However, when I try to do that, I am getting: > > Error: The constructor Rtag expects 4 argument(s), > but is applied here to 1 argument(s) > > This: > > | [Rtag (f1,f2,f3,f4)] -> > f1,f2,f3,f4 > > of course works but (regardless of the chosen bound variable names), it > looks amateurish. > > What's the right way to do this? > (I would like just to bind a 4-tuple and then return it) > > (Apologies in advance for a stupid question.) > > [-- Attachment #2: Type: text/html, Size: 1286 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 14:16 ` vrotaru.md @ 2017-10-19 14:24 ` Matej Košík 2017-10-19 14:29 ` vrotaru.md 2017-10-19 14:31 ` Alan Schmitt 0 siblings, 2 replies; 9+ messages in thread From: Matej Košík @ 2017-10-19 14:24 UTC (permalink / raw) To: vrotaru.md; +Cc: caml-list [-- Attachment #1.1: Type: text/plain, Size: 1303 bytes --] On 10/19/2017 04:16 PM, vrotaru.md@gmail.com wrote: > [ Rtag (_,_,_,_) as rtag] -> rtag That is certainly possible. It is equivalent to: | [rtag] -> rtag but that's not what I am trying to do. :-/ Instead of the whole Rtag (something1, something2, something3, something4) I would like to bind just the 4-tuple (without the Rtag label). > > > On Thu, Oct 19, 2017, 16:39 Matej Košík <mail@matej-kosik.net <mailto:mail@matej-kosik.net>> wrote: > > Hi, > > I am trying to do simple pattern matching of these values: > https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 > > What I would like to do is: > > | [Rtag the_whole_4_tuple] -> > the_whole_4_tuple > > However, when I try to do that, I am getting: > > Error: The constructor Rtag expects 4 argument(s), > but is applied here to 1 argument(s) > > This: > > | [Rtag (f1,f2,f3,f4)] -> > f1,f2,f3,f4 > > of course works but (regardless of the chosen bound variable names), it looks amateurish. > > What's the right way to do this? > (I would like just to bind a 4-tuple and then return it) > > (Apologies in advance for a stupid question.) > [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 14:24 ` Matej Košík @ 2017-10-19 14:29 ` vrotaru.md 2017-10-19 14:30 ` Olivier Nicole 2017-10-19 14:31 ` Alan Schmitt 1 sibling, 1 reply; 9+ messages in thread From: vrotaru.md @ 2017-10-19 14:29 UTC (permalink / raw) To: Matej Košík; +Cc: caml-list [-- Attachment #1: Type: text/plain, Size: 1520 bytes --] Rtag ((_,_,_,_) as t4) -> t4 Will this work? Writing from the phone On Thu, Oct 19, 2017, 17:24 Matej Košík <mail@matej-kosik.net> wrote: > On 10/19/2017 04:16 PM, vrotaru.md@gmail.com wrote: > > [ Rtag (_,_,_,_) as rtag] -> rtag > > That is certainly possible. > It is equivalent to: > > | [rtag] -> rtag > > but that's not what I am trying to do. :-/ > > Instead of the whole > > Rtag (something1, something2, something3, something4) > > I would like to bind just the 4-tuple > (without the Rtag label). > > > > > > > On Thu, Oct 19, 2017, 16:39 Matej Košík <mail@matej-kosik.net <mailto: > mail@matej-kosik.net>> wrote: > > > > Hi, > > > > I am trying to do simple pattern matching of these values: > > https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 > > > > What I would like to do is: > > > > | [Rtag the_whole_4_tuple] -> > > the_whole_4_tuple > > > > However, when I try to do that, I am getting: > > > > Error: The constructor Rtag expects 4 argument(s), > > but is applied here to 1 argument(s) > > > > This: > > > > | [Rtag (f1,f2,f3,f4)] -> > > f1,f2,f3,f4 > > > > of course works but (regardless of the chosen bound variable names), > it looks amateurish. > > > > What's the right way to do this? > > (I would like just to bind a 4-tuple and then return it) > > > > (Apologies in advance for a stupid question.) > > > > [-- Attachment #2: Type: text/html, Size: 2357 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 14:29 ` vrotaru.md @ 2017-10-19 14:30 ` Olivier Nicole 0 siblings, 0 replies; 9+ messages in thread From: Olivier Nicole @ 2017-10-19 14:30 UTC (permalink / raw) To: caml-list Hello, On 10/19/2017 04:29 PM, vrotaru.md@gmail.com wrote: > Rtag ((_,_,_,_) as t4) -> t4 > > Will this work? Writing from the phone No, this will complain that the Rtag constructor expects 4 arguments. I would say that what you are trying to do is not possible, but I'm not absolutely certain. > > > On Thu, Oct 19, 2017, 17:24 Matej Košík <mail@matej-kosik.net > <mailto:mail@matej-kosik.net>> wrote: > > On 10/19/2017 04:16 PM, vrotaru.md@gmail.com > <mailto:vrotaru.md@gmail.com> wrote: > > [ Rtag (_,_,_,_) as rtag] -> rtag > > That is certainly possible. > It is equivalent to: > > | [rtag] -> rtag > > but that's not what I am trying to do. :-/ > > Instead of the whole > > Rtag (something1, something2, something3, something4) > > I would like to bind just the 4-tuple > (without the Rtag label). > > > > > > > On Thu, Oct 19, 2017, 16:39 Matej Košík <mail@matej-kosik.net > <mailto:mail@matej-kosik.net> <mailto:mail@matej-kosik.net > <mailto:mail@matej-kosik.net>>> wrote: > > > > Hi, > > > > I am trying to do simple pattern matching of these values: > > > https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 > > > > What I would like to do is: > > > > | [Rtag the_whole_4_tuple] -> > > the_whole_4_tuple > > > > However, when I try to do that, I am getting: > > > > Error: The constructor Rtag expects 4 argument(s), > > but is applied here to 1 argument(s) > > > > This: > > > > | [Rtag (f1,f2,f3,f4)] -> > > f1,f2,f3,f4 > > > > of course works but (regardless of the chosen bound variable > names), it looks amateurish. > > > > What's the right way to do this? > > (I would like just to bind a 4-tuple and then return it) > > > > (Apologies in advance for a stupid question.) > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 14:24 ` Matej Košík 2017-10-19 14:29 ` vrotaru.md @ 2017-10-19 14:31 ` Alan Schmitt 1 sibling, 0 replies; 9+ messages in thread From: Alan Schmitt @ 2017-10-19 14:31 UTC (permalink / raw) To: Matej Košík; +Cc: vrotaru.md, caml-list [-- Attachment #1: Type: text/plain, Size: 517 bytes --] On 2017-10-19 16:24, Matej Košík <mail@matej-kosik.net> writes: > Instead of the whole > > Rtag (something1, something2, something3, something4) > > I would like to bind just the 4-tuple > (without the Rtag label). I think it is not possible because the memory layout is not the same (you need to destructure the Rtag block and create a new block for the tuple). Best, Alan -- OpenPGP Key ID : 040D0A3B4ED2E5C7 Monthly Athmospheric CO₂, Mauna Loa Obs. 2017-09: 403.38, 2016-09: 401.03 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 487 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 13:38 [Caml-list] beginner question about pattern matching Matej Košík 2017-10-19 14:16 ` vrotaru.md @ 2017-10-19 14:34 ` Gabriel Scherer 2017-10-19 14:40 ` Matej Košík 2017-10-19 14:44 ` vrotaru.md 1 sibling, 2 replies; 9+ messages in thread From: Gabriel Scherer @ 2017-10-19 14:34 UTC (permalink / raw) To: Matej Košík; +Cc: caml users This is a small hiccup with the OCaml (non-revised) syntax: | Foo of bar * baz * blah and | Foo of (bar * baz * blah) are not equivalent, and only the latter allows to do what you want. On Thu, Oct 19, 2017 at 3:38 PM, Matej Košík <mail@matej-kosik.net> wrote: > Hi, > > I am trying to do simple pattern matching of these values: > https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 > > What I would like to do is: > > | [Rtag the_whole_4_tuple] -> > the_whole_4_tuple > > However, when I try to do that, I am getting: > > Error: The constructor Rtag expects 4 argument(s), > but is applied here to 1 argument(s) > > This: > > | [Rtag (f1,f2,f3,f4)] -> > f1,f2,f3,f4 > > of course works but (regardless of the chosen bound variable names), it looks amateurish. > > What's the right way to do this? > (I would like just to bind a 4-tuple and then return it) > > (Apologies in advance for a stupid question.) > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 14:34 ` Gabriel Scherer @ 2017-10-19 14:40 ` Matej Košík 2017-10-19 14:44 ` vrotaru.md 1 sibling, 0 replies; 9+ messages in thread From: Matej Košík @ 2017-10-19 14:40 UTC (permalink / raw) To: caml-list [-- Attachment #1.1: Type: text/plain, Size: 1415 bytes --] Ok. Thank you all. I suspected as much but I wanted to check with someone else. (Adding a note about n+1-st note about Ocaml quirks and moving on.) (* NOTE: This looks bad, but Ocaml (4.06 beta) does not allow me to do any better *) | [Rtag (f1,f2,f3,f4)] -> f1,f2,f3,f4 On 10/19/2017 04:34 PM, Gabriel Scherer wrote: > This is a small hiccup with the OCaml (non-revised) syntax: > > | Foo of bar * baz * blah > > and > > | Foo of (bar * baz * blah) > > are not equivalent, and only the latter allows to do what you want. > > > On Thu, Oct 19, 2017 at 3:38 PM, Matej Košík <mail@matej-kosik.net> wrote: >> Hi, >> >> I am trying to do simple pattern matching of these values: >> https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 >> >> What I would like to do is: >> >> | [Rtag the_whole_4_tuple] -> >> the_whole_4_tuple >> >> However, when I try to do that, I am getting: >> >> Error: The constructor Rtag expects 4 argument(s), >> but is applied here to 1 argument(s) >> >> This: >> >> | [Rtag (f1,f2,f3,f4)] -> >> f1,f2,f3,f4 >> >> of course works but (regardless of the chosen bound variable names), it looks amateurish. >> >> What's the right way to do this? >> (I would like just to bind a 4-tuple and then return it) >> >> (Apologies in advance for a stupid question.) >> > [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] beginner question about pattern matching 2017-10-19 14:34 ` Gabriel Scherer 2017-10-19 14:40 ` Matej Košík @ 2017-10-19 14:44 ` vrotaru.md 1 sibling, 0 replies; 9+ messages in thread From: vrotaru.md @ 2017-10-19 14:44 UTC (permalink / raw) To: Gabriel Scherer; +Cc: Matej Košík, caml users [-- Attachment #1: Type: text/plain, Size: 1551 bytes --] I see, where I was wrong. But if the goal is to avoid allocation then something like [ Rtag (x, y, z, w)] -> somefn x y z w will work On Thu, Oct 19, 2017, 17:35 Gabriel Scherer <gabriel.scherer@gmail.com> wrote: > This is a small hiccup with the OCaml (non-revised) syntax: > > | Foo of bar * baz * blah > > and > > | Foo of (bar * baz * blah) > > are not equivalent, and only the latter allows to do what you want. > > > On Thu, Oct 19, 2017 at 3:38 PM, Matej Košík <mail@matej-kosik.net> wrote: > > Hi, > > > > I am trying to do simple pattern matching of these values: > > https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L145 > > > > What I would like to do is: > > > > | [Rtag the_whole_4_tuple] -> > > the_whole_4_tuple > > > > However, when I try to do that, I am getting: > > > > Error: The constructor Rtag expects 4 argument(s), > > but is applied here to 1 argument(s) > > > > This: > > > > | [Rtag (f1,f2,f3,f4)] -> > > f1,f2,f3,f4 > > > > of course works but (regardless of the chosen bound variable names), it > looks amateurish. > > > > What's the right way to do this? > > (I would like just to bind a 4-tuple and then return it) > > > > (Apologies in advance for a stupid question.) > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs [-- Attachment #2: Type: text/html, Size: 2476 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-10-19 14:44 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-10-19 13:38 [Caml-list] beginner question about pattern matching Matej Košík 2017-10-19 14:16 ` vrotaru.md 2017-10-19 14:24 ` Matej Košík 2017-10-19 14:29 ` vrotaru.md 2017-10-19 14:30 ` Olivier Nicole 2017-10-19 14:31 ` Alan Schmitt 2017-10-19 14:34 ` Gabriel Scherer 2017-10-19 14:40 ` Matej Košík 2017-10-19 14:44 ` vrotaru.md
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox