Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.functional > #102
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Brian Adkins <lojicdotcom@gmail.com> |
| Newsgroups | comp.lang.functional |
| Subject | Re: Converting list comprehensions to Standard ML |
| Date | Sun, 22 May 2011 12:56:31 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 34 |
| Message-ID | <m2lixyk728.fsf@gmail.com> (permalink) |
| References | <m21uzrhezi.fsf@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx04.eternal-september.org; posting-host="1hRJk2m14aRWSp6vwasOlQ"; logging-data="27563"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xxBYNfSJ9qfTZ54kqhDGv" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) |
| Cancel-Lock | sha1:ASYImMANrwAFa3UWF9mk1JmCBCA= sha1:+8NL4H1UDQMjFIwMjhCxhQKnJvA= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.functional:102 |
Show key headers only | View raw
Brian Adkins <lojicdotcom@gmail.com> writes:
> I've been translating a simple Haskell program I wrote to Standard ML,
> and I just bumped up agains this list comprehension:
>
> [ (r,c) | r <- [0..4], c <- [0..r], predicate (r,c) ]
>
> I don't think I appreciated the brevity of list comprehensions that much
> until I attempted to convert this :)
>
> What would be the most idiomatic way to implement this in Standard ML?
> The fact that the second generator depends on the first complicates
> things somewhat.
This is my first draft (with a little help from "ML for the Working
Programmer" by Paulsen):
(List.filter
(fn (r,c) => predicate (r,c))
(foldr (fn (r,l) => foldr (fn (c,l) => (r,c)::l) l (upto(0,r)))
[] (upto(0,4))))
I'm hoping there's a much better way though, because this seems *much*
less clear than the list comprehension.
By the way, is there a way to not have to write List.filter by using an
include or similar statement?
Thanks,
Brian
--
Brian Adkins
http://lojic.com/
Back to comp.lang.functional | Previous | Next — Previous in thread | Next in thread | Find similar
Converting list comprehensions to Standard ML Brian Adkins <lojicdotcom@gmail.com> - 2011-05-21 18:21 -0400
Re: Converting list comprehensions to Standard ML Brian Adkins <lojicdotcom@gmail.com> - 2011-05-22 12:56 -0400
Re: Converting list comprehensions to Standard ML torbenm@diku.dk (Torben Ægidius Mogensen) - 2011-05-23 10:46 +0200
Re: Converting list comprehensions to Standard ML Thomas Thiel <thomas.thiel13@freenet.de> - 2011-05-28 23:31 +0200
Re: Converting list comprehensions to Standard ML Brian Adkins <lojicdotcom@gmail.com> - 2011-06-04 19:54 -0400
Re: Converting list comprehensions to Standard ML torbenm@diku.dk (Torben Ægidius Mogensen) - 2011-05-23 14:33 +0200
Re: Converting list comprehensions to Standard ML torbenm@diku.dk (Torben Ægidius Mogensen) - 2011-05-23 17:48 +0200
Re: Converting list comprehensions to Standard ML Brian Adkins <lojicdotcom@gmail.com> - 2011-05-25 17:08 -0400
csiph-web