Answering my own question, one can achieve the goal via doing a lookup, if the number of possible parameters is limited.
eg. assume add is a function which can only take Int's from [0..9].
Interestingly, my situation is exactly like this. I think I'll implement such a lookup.
The question is still open though, if somebody has some magic to extract the prameter from an applied function...
Sorry, no good.
I don't want to guess the first paramater, I really want to access it.
2009/11/28 Steffen Schuldenzucker <sschuldenzucker@uni-bonn.de>
Ozgur Akgun wrote:Well, sure you can:
> 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)
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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
--
Ozgur Akgun