A purely haskell discussion, without any J code, probably belongs in the chat forum instead of this one.
That said, I think the point was not list comprehensions, but a question about what aspect was being referred to *instead of* list comprehensions. That is, if I comprehend the messages which have been recently posted to this list. Just saying... Thanks, -- Raul On Sat, Dec 27, 2014 at 12:41 PM, Stefano Lanzavecchia <s...@apl.it> wrote: > https://www.haskell.org/haskellwiki/List_comprehension > > On 27 December 2014 at 18:31, Aai <agroeneveld...@gmail.com> wrote: > >> Ok, I misinterpreted this enormously (I was just focused on the Haslell >> expression you started with). It would be nice if you could illustrate your >> last mail with an example in Haskell (but that's specifically for me). >> >> You started with the Haskell expression >> >> [ f x | x <- xs ] >> >> and described that as follows >> >> which means >> "the list of all f x >> such that x is drawn from xs." >> >> But in my opion it is more like: >> >> Apply function f on all x element of the list xs and of course f can be a >> very complex expression. As I said before this is often expressed with the >> higher order function map. >> >> >> >> >> >> Jon Hough schreef op 27-12-14 om 16:01: >> >> Hi Aai, >>> >>> I'm sorry, we may be talking past each other. You are correct abut list >>> comprehensions, but I am interested in being able to get a "such that" idea >>> in J, to make translating math definitions {A | B} (A such that B) into >>> computable J. >>> >>> This isn't to make anything computationally faster or anytihng like that, >>> it's for the ease of the human to understand what the conditions for >>> creating a set (or list or array ) is. >>> >>> As a simple example, the group C4 (cyclic group on 4 letters) is >>> 0 1 2 3 >>> 1 2 3 0 >>> 2 3 0 1 >>> 3 0 1 2 >>> (where each row is a permutation) >>> This group can be defined (in standard math notation, not J) as >>> >>> < x | order(x) == 4> >>> where angle brackets replace curly brackets to denote "generated by". >>> That is, we get the set of permutations generated by a permutation of order >>> 4. >>> >>> I'm sure there are several ways to get this set in J, but the one I am >>> interested in needs some sort of "such that" clause to keep it as close as >>> possible to the mathematical notation. >>> >>> So I can do: >>> >>> >>> >>> x =: (sym 4) where (4&=@:order)This gives a set of permutations from Sym >>> 4 that have order 4. I just want one. >>> generatorList =: 2 4 $ ((i. 4) , {. x) >>> I take the head of the list and append the identity permutation to it and >>> then use >>> generate generatorList >>> which should give me the Cyclic group on 4 letters.(where "generate" is >>> the verb m35 found here http://www.jsoftware.com/phrases/permutations.htm >>> ) >>> This actually works well I think, because it gives a flexible way to >>> change the conditional clause and create different sets, groups. >>> >>> >>> >>> >>> Date: Sat, 27 Dec 2014 15:44:10 +0100 >>>> From: agroeneveld...@gmail.com >>>> To: programm...@jsoftware.com >>>> Subject: Re: [Jprogramming] "Such that" syntax in J >>>> >>>> Hello John, >>>> >>>> just interpreting what you mean (but I may misunderstand it completely). >>>> With a list comprehension you can formulate: >>>> (just a simple example) >>>> >>>> Prelude> take 6 $ [ (^2) x | x <- [0..], 0 == x `mod` 2] >>>> [0,4,16,36,64,100] >>>> >>>> In J: >>>> >>>> (*:#~0=2&|) i.12 >>>> 0 4 16 36 64 100 >>>> >>>> Perhaps something like this? >>>> >>>> >>>> Jon Hough schreef op 27-12-14 om 15:26: >>>> >>>>> Hi Aai, >>>>> >>>>> I see what you are saying, but I would say that implicitly inside f >>>>> there is some sort of "such that" syntax. >>>>> My motivation for asking for a "such that / where" construct is to >>>>> create computable math definitions, as in Haskell. >>>>> >>>>> for example, if I want the set (or group): >>>>> >>>>> { x e. Sym(4) | order(x) = 4} (where Sym(4) is the symmetric group on 4 >>>>> letters) >>>>> >>>>> then, assuming I have a verb "sym" and a verb "order" I can do >>>>> >>>>> >>>>> (sym 4) where (4&=@:order) >>>>> Then it may just be possible to generate groups from group >>>>> presentations ( http://en.wikipedia.org/wiki/Presentation_of_a_group)(I >>>>> haven't figured out how to do this, I am just thinking about it over the >>>>> holidays) >>>>> >>>>> Date: Sat, 27 Dec 2014 08:46:12 +0100 >>>>>> From: agroeneveld...@gmail.com >>>>>> To: programm...@jsoftware.com >>>>>> Subject: Re: [Jprogramming] "Such that" syntax in J >>>>>> >>>>>> Sorry for jumping in late. >>>>>> >>>>>> The Haskell expression you showed here is called a list comprehansion >>>>>> which can be easily formulated as >>>>>> >>>>>> map f xs >>>>>> >>>>>> and this is in J simply: >>>>>> >>>>>> f xs >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Jon Hough schreef op 26-12-14 om 17:04: >>>>>> >>>>>>> In Haskell (and other languages I'm sure) one can express the idea of >>>>>>> "such that" to denote one expression depending on another. In Haskell we >>>>>>> can use the syntax: >>>>>>> >>>>>>> [ f x | x <- xs ] >>>>>>> >>>>>>> which means >>>>>>> "the list of all f x >>>>>>> such that x is drawn from xs." >>>>>>> >>>>>>> So | is syntactically similar to the English "such that". (and very >>>>>>> much like | in mathematical sets) >>>>>>> >>>>>>> I would like to know if J has a construct to express the above >>>>>>> Haskell code. >>>>>>> >>>>>>> Thanks, >>>>>>> Jon. >>>>>>> >>>>>>> ------------------------------------------------------------ >>>>>>> ---------- >>>>>>> For information about J forums see http://www.jsoftware.com/ >>>>>>> forums.htm >>>>>>> >>>>>> -- >>>>>> Met vriendelijke groet, >>>>>> @@i = Arie Groeneveld >>>>>> >>>>>> ---------------------------------------------------------------------- >>>>>> For information about J forums see http://www.jsoftware.com/forums.htm >>>>>> >>>>> >>>>> ---------------------------------------------------------------------- >>>>> For information about J forums see http://www.jsoftware.com/forums.htm >>>>> >>>> -- >>>> Met vriendelijke groet, >>>> @@i = Arie Groeneveld >>>> >>>> ---------------------------------------------------------------------- >>>> For information about J forums see http://www.jsoftware.com/forums.htm >>>> >>> >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >> >> -- >> Met vriendelijke groet, >> @@i = Arie Groeneveld >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm