Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: map question (Will Ness) 2. Re: Re: map question (Daniel Fischer) 3. Re: Re: map question (Daniel Fischer) 4. \x -> x < 0.5 && x > -0.5 (Michael Mossey) 5. Re: \x -> x < 0.5 && x > -0.5 (Magnus Therning) 6. Re: \x -> x < 0.5 && x > -0.5 (Krzysztof Skrz?tnicki) 7. RE: \x -> x < 0.5 && x > -0.5 (Luca Ciciriello) 8. Re: \x -> x < 0.5 && x > -0.5 (Heinrich Apfelmus) 9. Re: \x -> x < 0.5 && x > -0.5 (Christian Maeder) 10. Re: Re: \x -> x < 0.5 && x > -0.5 (Paul Visschers) ---------------------------------------------------------------------- Message: 1 Date: Sun, 18 Oct 2009 22:32:31 +0000 (UTC) From: Will Ness <will_...@yahoo.com> Subject: [Haskell-beginners] Re: map question To: beginners@haskell.org Message-ID: <loom.20091019t002932...@post.gmane.org> Content-Type: text/plain; charset=us-ascii Deniz Dogan <deniz.a.m.dogan <at> gmail.com> writes: > 2009/10/18 Will Ness <will_n48 <at> yahoo.com>: > > > > exactly, just that it would be a _binary_ (-) . > > So the only case where `(this)` syntax would be useful is where you > want to make GHC understand you mean the binary (-) operator and you > want to use point-free code. Now you have the choice between `(-)` and > subtract, which one will it be? :) subtract = flip (-) -- binary (`-`) = (-) -- binary The only one place where I'd like to use it, is in (`-`2), instead of (flip (-) 2) or (subtract 2) or (\a->a-2) or anything else. Also, it is not `(-)` syntax that I'm advocating for, but `-` syntax, in sections, to guide the selection of the operator's _binary_ version over its _unary_ version. Actually, I suspect there is no unary (-), but rather in (-2) the "-" is a part of number read syntax. Having it enclosed in backticks would stop it being read as a part of a number, and thus ensure it being correctly interpreted as an operator, binary as any other Haskell operator: Prelude> :t (-) (-) :: (Num a) => a -> a -> a Prelude> :t (`-`2) <interactive>:1:2: parse error on input `-' Even (`-`) may be left as invalid syntax, as it is today: Prelude> :t (`foldl`) <interactive>:1:8: parse error on input `)' Prelude> :t (`foldl`0) (`foldl`0) :: (Num a) => (a -> b -> a) -> [b] -> a ------------------------------ Message: 2 Date: Mon, 19 Oct 2009 02:27:42 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] Re: map question To: beginners@haskell.org Cc: Will Ness <will_...@yahoo.com> Message-ID: <200910190227.42750.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" Am Sonntag 18 Oktober 2009 22:40:46 schrieb Will Ness: > Daniel Fischer <daniel.is.fischer <at> web.de> writes: > > Am Sonntag 18 Oktober 2009 13:11:07 schrieb Will Ness: > > > backticks could've been made no-op for operators. What's so wrong with > > > (`:`[])? It'd just be the same as (:[]). > > > > Makes writing the parser more complicated. > > Makes reading code more irritating. > > I suspected as much, but if it has some benefits, that would be justified. I think you mean "if the benefits outweigh the downsides". If they do (or rather, if enough people believe they do and few enough believe it's the other way round), then it's justified. As of now, I don't believe it has substantial benefits (consequences which I regard as benefits). > > > > Except for `-`, where it would finally provide us with possibility to > > > write a shortcut for the ugly (flip (-) 1) as (`-`1). > > > > That's ugly too. > > My favourite is subtract 1. > > We could write (hypothetically) 'concatenate' for ++ too, but we don't. > What's so great with writing out long names, that should be processed, > mentally, to get at their meaning, when we have this nice operators syntax > which makes the meaning immediately - visibly - apparent? Operator syntax per se doesn't make the meaning immediately apparent. Only the meaning of well known operators (like +,-,*,/) and, to some extent, close derivations of them (like ++) is readily apparent. ($) or (>>=) aren't obvious when you first see them. However, I didn't want to advocate the use of alphabetic identifiers instead of operators, I meant that since (- 1) doesn't work, my favourite way to express it is (subtract 1). I find that nicer than (flip (-) 1), and also aesthetically superior to (`-` 1). Purely personal taste, of course. > > The only problem in Haskell syntax is this unary-over-binary (-), so Yes, that's unpleasant. However, for me it's a minor point. > allowing backticks for operators as well as for regular names would finally > provide a solution for it. > > Nobody would use it except for (-) sections. Are you sure? People abuse every oportunity you give them and then some, so I wouldn't be too surprised if gratuitous backticks seeped into Haskell code over time. > Or even, hypothetically, it > could be used to allow unary operators in the language, in general. That > whould be a mechanism for distinguishing the binary from the unary > versions. > > Why not? Difficulty of writing a parser is not a valid reason if there's a > clear utility in it. IMHO. ------------------------------ Message: 3 Date: Mon, 19 Oct 2009 02:36:14 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] Re: map question To: beginners@haskell.org Cc: Will Ness <will_...@yahoo.com> Message-ID: <200910190236.14834.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" Am Sonntag 18 Oktober 2009 22:57:38 schrieb Will Ness: > Daniel Fischer <daniel.is.fischer <at> web.de> writes: > > Am Sonntag 18 Oktober 2009 13:11:07 schrieb Will Ness: > > > (2`mod`) is a unary operation :: (Integral a) => a -> a. Putting it > > > inside backticks would require it be a binary infix op, causing a type > > > mis-match. > > > > instance (Integral a) => Integral (b -> a) where ... > > > > Evil, yes, but then f `(2 `mod`)` x would type-check. > > Any problem that could be introduced for operators could be introduced for > the regular named values as well. But allowing only one level of backticks, and only on plain identifiers limits the scope of possible problems. > > > But anyway, there are operators where a backticked section would > > type-check: > > > > f `(g `.`)` x > > > > That's not good. > > Why? Is it not just (g .) f x ? What's the problem with it? It's incredibly ugly, looks almost like a perl regex. ------------------------------ Message: 4 Date: Mon, 19 Oct 2009 01:49:17 -0700 From: Michael Mossey <m...@alumni.caltech.edu> Subject: [Haskell-beginners] \x -> x < 0.5 && x > -0.5 To: beginners@haskell.org Message-ID: <4adc280d.1070...@alumni.caltech.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Is there a nifty way to write filter (\x -> x < 0.5 && x > -0.5) xs without explicitly using x? Maybe arrows? I have a vague understanding that arrows can "send" an argument to more than one computation. -Mike ------------------------------ Message: 5 Date: Mon, 19 Oct 2009 10:03:50 +0100 From: Magnus Therning <mag...@therning.org> Subject: Re: [Haskell-beginners] \x -> x < 0.5 && x > -0.5 To: Michael Mossey <m...@alumni.caltech.edu> Cc: beginners@haskell.org Message-ID: <e040b520910190203s3170a7cfh25b667699d710...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Oct 19, 2009 at 9:49 AM, Michael Mossey <m...@alumni.caltech.edu> wrote: > Is there a nifty way to write > > filter (\x -> x < 0.5 && x > -0.5) xs > > without explicitly using x? > > Maybe arrows? I have a vague understanding that arrows can "send" an > argument to more than one computation. Using &&& from Control.Arrow you can write something like file (uncurry (&&) . ((< 0.5) &&& (> -0.5))) xs /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org http://therning.org/magnus identi.ca|twitter: magthe ------------------------------ Message: 6 Date: Mon, 19 Oct 2009 11:05:20 +0200 From: Krzysztof Skrz?tnicki <gte...@gmail.com> Subject: Re: [Haskell-beginners] \x -> x < 0.5 && x > -0.5 To: Michael Mossey <m...@alumni.caltech.edu> Cc: beginners@haskell.org Message-ID: <220e47b40910190205t53152eb5jb28575cf74270...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Oct 19, 2009 at 10:49, Michael Mossey <m...@alumni.caltech.edu> wrote: > Is there a nifty way to write > > filter (\x -> x < 0.5 && x > -0.5) xs > > without explicitly using x? > > Maybe arrows? I have a vague understanding that arrows can "send" an > argument to more than one computation. You can do that with arrows like this: Prelude Control.Arrow> let rangeA x y = ((>x) &&& (<y)) >>> (uncurry (&&)) Prelude Control.Arrow> :t rangeA rangeA :: (Ord a) => a -> a -> a -> Bool Prelude Control.Arrow> filter (rangeA 4 8) [0..10] [5,6,7] Best regards Krzysztof SkrzÄtnicki ------------------------------ Message: 7 Date: Mon, 19 Oct 2009 10:22:26 +0100 From: Luca Ciciriello <luca_cicirie...@hotmail.com> Subject: RE: [Haskell-beginners] \x -> x < 0.5 && x > -0.5 To: <m...@alumni.caltech.edu>, <beginners@haskell.org> Message-ID: <snt128-w42f796812c69254976db539a...@phx.gbl> Content-Type: text/plain; charset="iso-8859-1" Had you considered list comprehension? [x | x <- xs, x < 0.5 && x > -0.5] Luca. > Date: Mon, 19 Oct 2009 01:49:17 -0700 > From: m...@alumni.caltech.edu > To: beginners@haskell.org > Subject: [Haskell-beginners] \x -> x < 0.5 && x > -0.5 > > Is there a nifty way to write > > filter (\x -> x < 0.5 && x > -0.5) xs > > without explicitly using x? > > Maybe arrows? I have a vague understanding that arrows can "send" an > argument to more than one computation. > > -Mike > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners _________________________________________________________________ Use Windows Live Messenger for free on selected mobiles http://clk.atdmt.com/UKM/go/174426567/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20091019/09a310c4/attachment-0001.html ------------------------------ Message: 8 Date: Mon, 19 Oct 2009 12:02:19 +0200 From: Heinrich Apfelmus <apfel...@quantentunnel.de> Subject: [Haskell-beginners] Re: \x -> x < 0.5 && x > -0.5 To: beginners@haskell.org Message-ID: <hbhdfc$ag...@ger.gmane.org> Content-Type: text/plain; charset=ISO-8859-1 Michael Mossey wrote: > Is there a nifty way to write > > filter (\x -> x < 0.5 && x > -0.5) xs > > without explicitly using x? > > Maybe arrows? I have a vague understanding that arrows can "send" an > argument to more than one computation. That's a job for the reader monad. Lambda Fu, form 53 - silent reader of truth import Control.Monad import Control.Monad.Reader filter (liftM2 (&&) (< 0.5) (> -0.5)) xs Regards, apfelmus -- http://apfelmus.nfshost.com ------------------------------ Message: 9 Date: Mon, 19 Oct 2009 12:07:19 +0200 From: Christian Maeder <christian.mae...@dfki.de> Subject: [Haskell-beginners] Re: \x -> x < 0.5 && x > -0.5 To: Michael Mossey <m...@alumni.caltech.edu> Cc: beginners@haskell.org Message-ID: <4adc3a57.4020...@dfki.de> Content-Type: text/plain; charset=ISO-8859-1 Michael Mossey schrieb: > Is there a nifty way to write > > filter (\x -> x < 0.5 && x > -0.5) xs > > without explicitly using x? Hoogle did not find a function of type: (b -> b -> b) -> (a -> b) -> (a -> b) -> a -> b or (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d But maybe such a function is worth being added to Data.Function. Cheers Christian ------------------------------ Message: 10 Date: Mon, 19 Oct 2009 12:11:30 +0200 From: Paul Visschers <m...@paulvisschers.net> Subject: Re: [Haskell-beginners] Re: \x -> x < 0.5 && x > -0.5 To: beginners@haskell.org Message-ID: <4adc3b52.4050...@paulvisschers.net> Content-Type: text/plain; charset=ISO-8859-1 Wouldn't it be better to make an instance of the Boolean class for functions, that way you could just write: filter ((< 0.5) && (> -0.5)) xs Not sure about the syntax, as the Haskell site is down. Also it will require that you install and import the Boolean class. One could ask if any of these methods are more readable than the original though. Paul Heinrich Apfelmus wrote: > Michael Mossey wrote: >> Is there a nifty way to write >> >> filter (\x -> x < 0.5 && x > -0.5) xs >> >> without explicitly using x? >> >> Maybe arrows? I have a vague understanding that arrows can "send" an >> argument to more than one computation. > > That's a job for the reader monad. > > > Lambda Fu, form 53 - silent reader of truth > > import Control.Monad > import Control.Monad.Reader > > filter (liftM2 (&&) (< 0.5) (> -0.5)) xs > > > > Regards, > apfelmus > > -- > http://apfelmus.nfshost.com > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 16, Issue 12 *****************************************