[Haskell-beginners] function multiple args

Ovidiu Deac ovidiudeac at gmail.com
Mon Dec 18 15:34:32 UTC 2017


I'm not sure I understand your intention but I will try to answer though.

Since your functions have different types you won't be able to put them in
the same collection.

Considering these two:

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

You have the following options:

1. You can have a sum type to wrap them

data MyFunctionType a =
    Vtype (Int -> [a] -> [a])
    | Wtype (Int -> Int -> [a] -> [a])

then you will have your collection

myFunctions = [VType v, WType w,...]

then, when you apply them you will have to match and apply the function
properly.

2. Another way to put them in the same collection could be to apply each of
the functions partially until you are left with functions having the type
([a] -> [a])

myFunctions = [v 10, w 1 2]

Does that answer your question?


On Sun, Dec 17, 2017 at 11:32 AM, mike h <mike_k_houghton at 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171218/cd1e0387/attachment.html>


More information about the Beginners mailing list