Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. The application of application (Christopher Howard)
2. Re: The application of application (Christopher Howard)
3. Re: The application of application (David Sabel)
4. Re: The application of application (Daniel Trstenjak)
----------------------------------------------------------------------
Message: 1
Date: Sat, 01 Dec 2012 13:31:03 -0900
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] The application of application
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Can application of an expression (to a function) be treated like a
function itself? In my specific case, I started with this expression:
code:
--------
(cos b * velocityC, sin b * velocityC)
--------
But I have a compulsive hatred of duplication. I happened to have this
function handy called appPair:
code:
-------
appPair f (a, b) = (f a, f b)
appPair (* velocityC) (cos b, sin b)
-------
Better, but the b identifier is still duplicated. Is there some way I
could have...
code:
--------
appPair (?) (cos, sin)
--------
...shifting the application of b into the (* velocityC) expression,
without modifying my appPair function?
--
frigidcode.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121201/9c5bbff9/attachment-0001.pgp>
------------------------------
Message: 2
Date: Sat, 01 Dec 2012 13:39:22 -0900
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] The application of application
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On 12/01/2012 01:31 PM, Christopher Howard wrote:
> Can application of an expression (to a function) be treated like a
> function itself? In my specific case, I started with this expression:
>
> code:
> --------
> (cos b * velocityC, sin b * velocityC)
> --------
>
> But I have a compulsive hatred of duplication. I happened to have this
> function handy called appPair:
>
> code:
> -------
> appPair f (a, b) = (f a, f b)
>
> appPair (* velocityC) (cos b, sin b)
> -------
>
> Better, but the b identifier is still duplicated. Is there some way I
> could have...
>
> code:
> --------
> appPair (?) (cos, sin)
> --------
>
> ...shifting the application of b into the (* velocityC) expression,
> without modifying my appPair function?
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
Wait, think I got it...
code:
--------
appPair (\x -> (x $ b) * velocityC) (cos, sin)
--------
--
frigidcode.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121201/519bdf15/attachment-0001.pgp>
------------------------------
Message: 3
Date: Sat, 01 Dec 2012 23:48:56 +0100
From: David Sabel <[email protected]>
Subject: Re: [Haskell-beginners] The application of application
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
A short derivation:
An obvious solution is: Use a lambda abstraction:
appPair (\x -> (x b) * velocityC) (cos,sin)
or (using function composition)
appPair ((* velocityC) . (\x -> x b))(cos,sin)
or (explictly using the application operator $):
appPair ((* velocityC) . (\x -> x $ b))(cos,sin)
Now the lambda abstraction can be removed
appPair ((* velocityC ) . ($ b)) (cos,sin)
Regards,
David
Am 01.12.2012 23:31, schrieb Christopher Howard:
> Can application of an expression (to a function) be treated like a
> function itself? In my specific case, I started with this expression:
>
> code:
> --------
> (cos b * velocityC, sin b * velocityC)
> --------
>
> But I have a compulsive hatred of duplication. I happened to have this
> function handy called appPair:
>
> code:
> -------
> appPair f (a, b) = (f a, f b)
>
> appPair (* velocityC) (cos b, sin b)
> -------
>
> Better, but the b identifier is still duplicated. Is there some way I
> could have...
>
> code:
> --------
> appPair (?) (cos, sin)
> --------
>
> ...shifting the application of b into the (* velocityC) expression,
> without modifying my appPair function?
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121201/fab295e3/attachment-0001.htm>
------------------------------
Message: 4
Date: Sun, 2 Dec 2012 10:31:31 +0100
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] The application of application
To: [email protected]
Message-ID: <20121202093131.GA2212@machine>
Content-Type: text/plain; charset=us-ascii
Hi Christopher,
On Sat, Dec 01, 2012 at 01:39:22PM -0900, Christopher Howard wrote:
> (cos b * velocityC, sin b * velocityC)
vs.
> appPair (\x -> (x $ b) * velocityC) (cos, sin)
Duplication isn't always a bad thing. Programming in Haskell can be
quite tempting for code golfing.
The first version is simpler, shorter and even understandable for non
Haskellers.
Sometimes the desire to look smart can result in quite horrible code.
Greetings,
Daniel
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 54, Issue 2
****************************************