[Haskell-beginners] The application of application
Kim-Ee Yeoh
ky3 at atamo.com
Sun Dec 2 12:07:04 CET 2012
On Sun, Dec 2, 2012 at 5:31 AM, Christopher Howard <
christopher.howard at frigidcode.com> wrote:
> But I have a compulsive hatred of duplication.
And thus haskell code golfing is born! Actually that's not always true. The
motivation is sometimes compellingly noble. E.g. we want a faithfully
compact translation of (English!)
"Given some number compute both its sine and cosine, both scaled by
velocityC."
into
import Control.Arrow( (***), (&&&) )
import Control.Monad( join )
f = join (***) (velocityC*) . (sin &&& cos)
Unfamiliarity with symbol-rich combinators has been known to exact
cognitive pain, leading to unfortunate comparisons with Perl. Evidently,
the story isn't always driven by sadism.
Credits: I asked a similar question years ago [1] and got a heap of useful
replies. Special mention to Robert Vollmert and Luke Palmer for help
arriving at the above version.
[1] http://www.haskell.org/pipermail/haskell-cafe/2009-February/056195.html
-- Kim-Ee
On Sun, Dec 2, 2012 at 5:31 AM, Christopher Howard <
christopher.howard at frigidcode.com> 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?
>
> --
> frigidcode.com
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121202/cd9bfd61/attachment.htm>
More information about the Beginners
mailing list