Re: [Haskell-cafe] Re: wanted: haskell one-liners (in the perl sense of one-liners)

You contributed
#12:14 < Thunder> @pl \s -> drop (length s - n) s
#12:14 < lambdabot> drop =<< subtract n . length
But, on second thought, 1) I can't use this as a drop-in replacement
for the non points free (right term?) version, and 2) I don't really
understand it.
Still, I would be curious to see if there is a way to make this useful somehow.
2007/3/20, Lutz Donnerhacke
In iks.lists.haskell, you wrote:
This takes a long file containing mostly numerical data, filters out the numerical data, and sorts it numerically. (Not the same thing as sorting alphabetically, which is what you get by default, or using the unix sort utility). Maybe there's some flag to make unix sort util act like this? Enh, who cares, now we have haskell. :)
sort -g
Thanks to Thunder
I was not that helpful.

* Thomas Hartman wrote:
You contributed
#12:14 < Thunder> @pl s -> drop (length s - n) s #12:14 < lambdabot> drop =<< subtract n . length
But, on second thought, 1) I can't use this as a drop-in replacement for the non points free (right term?) version, and 2) I don't really understand it.
I did not contribute, but polluted the channel with my own test. In order to understand this construct you have to switch to the (-> a) Monad: drop =<< subtract n . length == do x <- subtract n . length drop x This construct consists of partially applied functions, i.e. functions waiting for an argument. If you apply an argument to the whole construct, it is applied to each line seperatly. So "drop =<< subtract n . length $ s" becomes: let x = subtract n . length $ s in drop x s == let x = length s - n in drop x s == drop (length s - n) s I did not expect this monadic approach from lambdabot and was somewhat surprised. I assumed an application of "liftM2 drop" instead.
participants (2)
-
Lutz Donnerhacke
-
Thomas Hartman