From: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>
To: Yotam Barnoy <yotambarnoy@gmail.com>
Cc: David Allsopp <dra-news@metastack.com>,
Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Pattern matching on refs
Date: Fri, 11 Oct 2013 06:49:32 +0200 [thread overview]
Message-ID: <CAMoPVjfUxErjpYA1BcJvkK5==uBaS0dn-cn=TGbdZWWK_nJ=Sw@mail.gmail.com> (raw)
In-Reply-To: <CAN6ygOkbWq5p=2cNYYpWXV=vyK4UE1P+JLLEO7X6X-0AbVG5QQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2970 bytes --]
If you need queues with random access, and do not need highly tuned
performances, may I suggest you having a look at Okasaki's *Purely
functional datastructures*. It has a handful of these, which do not involve
assignment (they use laziness annotation, though, for good amortized
performances). It would make your life better. The book version has a
little more than the thesis, by the way.
On 10 October 2013 21:46, Yotam Barnoy <yotambarnoy@gmail.com> wrote:
> D'oh! I always forget about mutable fields somehow. Refs just take over in
> my mind and I end up putting them everywhere I need mutability. Shows how
> little I actually use mutability in ocaml.
>
> And the reason for the linked lists is that I need a (low-performance)
> queue/stack with random access. And the reason for implementing a
> doubly-linked list myself is that my advisor is against using any library
> that's not part of the ocaml distribution.
>
> Sorry for the disturbance folks. Move along!
>
> -Yotam
>
>
> On Thu, Oct 10, 2013 at 3:42 PM, David Allsopp <dra-news@metastack.com>wrote:
>
>> Yotam Barnoy wrote:
>> > I recently found out how ugly it is to pattern-match on a ref,
>> > using {contents=...}. This should be extremely easy to fix in
>> > the parser. Can it please be put into the next version of ocaml?
>>
>> I imagine there are those who might suggest that the ugliness of pattern
>> matching on refs is part of the discouragement against using them!
>>
>> > match x with
>> > | ref y -> ...
>>
>> I'm guessing that you're really pattern matching with refs inside tuples
>> or something which makes using !x impractical? That said, if you've ended
>> with up (foo, bar, baz) where at least one of those is a reference, why not
>> consider using records with mutable fields?
>>
>> While writing this, Yotam Barnoy wrote:
>> > It wouldn't solve the problem, because in reality
>> > I'm matching something like this piece of code
>> > implementing a doubly-linked list:
>> >
>> > type 'a cell = { data : 'a;
>> > next : 'a link ref;
>> > last : 'a link ref;
>> > }
>>
>> Completely ignoring why you might be implementing linked lists in a
>> list-processing language (I'm sure there's a good reason!), why not have
>>
>> type 'a cell = {data: 'a;
>> next: mutable 'a link;
>> last: mutable 'link}
>>
>> ?
>>
>> The parser change you propose is probably not trivial - for a start,
>> "ref" is part of the Pervasives module, not part of the grammar, and [ref]
>> itself can be redefined (try [let ref x = x] in the toplevel). Putting
>> something into the grammar to allow pattern matching on ref like this would
>> at best be a grim hack.
>>
>>
>> David
>>
>> --
>> 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: 4331 bytes --]
next prev parent reply other threads:[~2013-10-11 4:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-10 19:17 Yotam Barnoy
2013-10-10 19:34 ` Ashish Agarwal
2013-10-10 19:37 ` Yotam Barnoy
2013-10-10 19:42 ` David Allsopp
2013-10-10 19:46 ` Yotam Barnoy
2013-10-11 4:49 ` Arnaud Spiwack [this message]
2013-10-11 6:10 ` Francois Berenger
2013-10-10 20:23 ` Jacques Le Normand
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='CAMoPVjfUxErjpYA1BcJvkK5==uBaS0dn-cn=TGbdZWWK_nJ=Sw@mail.gmail.com' \
--to=aspiwack@lix.polytechnique.fr \
--cc=caml-list@inria.fr \
--cc=dra-news@metastack.com \
--cc=yotambarnoy@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