You can pattern match on the right hand side of '|' in a list
comprehension, since a list comprehension is just the list monad.
Just changed a few things.
Hopefully this answers the OP's question and any interested others.
add :: Int - Int - Int
add x y = x + y
-- a list of partially applied
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
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 =
Sorry, no good.
I don't want to guess the first paramater, I really want to access it.
2009/11/28 Steffen Schuldenzucker sschuldenzuc...@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
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
The question is still open though, if somebody has some magic to extract the
prameter from an applied function...
It isn't possible.
Closest solution will be a list of pairs (function,arg) and a special
apply function that takes those pairs and apply to function an
argument and.them, apply
-- Here's a expansion of the ideas presented for tracking the argument used
-- to create a partially applied function:
--
-- Based on simple pairs
--
add :: Int - Int - Int
add x y = x + y
addr :: Int - (Int, Int - Int)
addr a = (a, add a)
-- a list of partially applied functions
adds = [addr
Will the following do what you wish?
add :: Int - Int - Int
add x y = x + y
addends = [3,5,7,3,5,8]::[Int]
add3s :: [Int] - [Int - Int]
add3s addends = map add (filter (3==) addends)
k3 :: [Int]
k3 = map (\ f - f 10 ) (add3s addends)
--
Regards,
Casey
Will the following do what you wish?
add :: Int - Int - Int
add x y = x + y
addends = [3,5,7,3,5,8]::[Int]
-- P for predicate
addPs :: (Int - Bool) - [Int] - [Int - Int]
addPs predicate addends = map add (filter predicate addends)
kP :: [Int]
kP = map (\ f - f 10 ) (addPs (3==) addends)
--
On Nov 28, 2009, at 12:01 , Ozgur Akgun wrote:
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
It sounds as if you want to carry some state around for each partially
applied function, I think that's in monad territory.
A cardinal rule of functional programming is to create new data,
whenever possible.
--
Regards,
Casey
___
Haskell-Cafe mailing
You can pattern match on the right hand side of '|' in a list
comprehension, since a list comprehension is just the list monad.
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
kP
12 matches
Mail list logo