[Haskell-cafe] Partially applied functions
ozgurakgun at gmail.com
Sat Nov 28 11:56:27 EST 2009
Sorry, no good.
I don't want to guess the first paramater, I really want to access it.
2009/11/28 Steffen Schuldenzucker <sschuldenzucker at uni-bonn.de>
> Ozgur Akgun wrote:
> > Hi cafe,
> > Is such a thing possible,
> > add :: Int -> Int -> Int
> > add x y = x + y
> > -- a list of partially applied functions
> > adds = [add 3, add 5, add 7, add 3, add 5, add 8]
> > -- an example usage of the list
> > k = map (\ f -> f 10 ) adds
> > add3s = filter (?) adds -- add3s = [add 3, add 3]
> > addEvens = filter (?) adds --addEvens = [add 8]
> > I want to have functions in place of the ? signs. I guess one would need
> > a way of extracting the applied value from a partially applied function
> > (or totally, doesn't matter)
> Well, sure you can:
> add3s = filter (\f -> f 0 == 3) adds
> addEvens = filter (\f -> isEven $ f 0) adds
> This is only possible since there is that special property of the
> addition that (add a) 0 == a forall a, i.e. you can extract the first
> parameter back out of the partial applied function by passing 0 as a
> second parameter.
> It clearly depends on the function how much information about the
> parameters can be read from the result.
> -- Steffen
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe