Thanks Stuart, Ovidiu. Yes, partially applied functions is the way.

Mike

On 18 Dec 2017, at 16:00, Stuart Dootson <stuart.dootson@gmail.com> wrote:

Something like the code below - populate a list with partially applied functions, then use foldl to apply the functions in turn to the input list?

v :: Int -> [a] -> [a]
v = drop

w :: Int -> Int -> [a] -> [a]
w keep reject = (take keep).(drop reject)

-- Apply the list of functions (in turn) to the list, yielding a list
apply_ops :: [ [a] -> [a] ] -> [a] -> [a]
apply_ops fns l = foldl (flip ($)) l fns

-- Partially apply functions with non-list arguments to get list of functions of type [a] -> [a]
ops :: [ [a] -> [a] ]
ops = [v 3, w 2 1]

-- result = (w 2 1) ((v 3)[1,2,3,4,5,6,7,8])
--        = w [4,5,6,7,8]
--        = [5,6]
result :: [Int]
result = apply_ops ops [1,2,3,4,5,6,7,8]

main =
  do
    print result

On 17 December 2017 at 09:32, mike h <mike_k_houghton@yahoo.co.uk> wrote:
Hi,

I have a number of functions like these:

v :: Int -> [a] -> [a]
w :: Int -> Int -> [a] -> [a]
x :: a -> a -> [a] -> [a]

y :: a -> b ->…  <other args>... ->  [a] -> [a]
z…
etc.

where there are any number of args of different types but the last two are common to all the functions i.e. they all have  [a] -> [a]

What I’m trying to do is build a collection (ordered) of such functions and then apply each in turn to a [a] to get the final [a]. What would be the best approach to this?

Thanks

Mike
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners