[Haskell-cafe] calling a variable length parameter lambda expression

Victor Nazarov asviraspossible at gmail.com
Thu May 7 04:40:28 EDT 2009


On Wed, May 6, 2009 at 7:44 PM, Daniel Peebles <pumpkingod at gmail.com> wrote:

> Keep in mind that using lists for your parameters means you lose
> static guarantees that you've passed the correct number of arguments
> to a function (so you could crash at runtime if you pass too few or
> too many parameters to a function).
>

Yes, program will crash with error "Pattern match failure" or smth like
that. And yes, doLam is just an id with restricted type. My solution is
close to what seems the most common way of passing arguments in Scheme, and
the payoff is Scheme's dynamic typing...

This solution is not the Haskell way and should be avoid.

--
Victor Nazarov


> On Wed, May 6, 2009 at 11:41 AM, Nico Rolle <nrolle at web.de> wrote:
> > super nice.
> > best solution for me so far.
> > big thanks.
> > regards
> >
> > 2009/5/6 Victor Nazarov <asviraspossible at gmail.com>:
> >> On Tue, May 5, 2009 at 8:49 PM, Nico Rolle <nrolle at web.de> wrote:
> >>>
> >>> Hi everyone.
> >>>
> >>> I have a problem.
> >>> A function is recieving a lambda expression like this:
> >>> (\ x y -> x > y)
> >>> or like this
> >>> (\ x y z a -> (x > y) && (z < a)
> >>>
> >>> my problem is now i know i have a list filled with the parameters for
> >>> the lambda expression.
> >>> but how can i call that expression?
> >>> [parameters] is my list of parameters for the lambda expression.
> >>> lambda_ex is my lambda expression
> >>>
> >>> is there a function wich can do smth like that?
> >>>
> >>> lambda _ex (unfold_parameters parameters)
> >>
> >> Why not:
> >>
> >> lam1 = \[x, y] -> x > y
> >> lam2 = \[x, y, z, a] -> (x > y) && (z < a)
> >>
> >> doLam :: Ord a => ([a] -> Bool) -> [a] -> Bool
> >> doLam lam params = lam params
> >>
> >> So, this will work fine:
> >>
> >> doLam lam1 [1, 2]
> >> doLam lam2 [1,2,3,4]
> >>
> >> --
> >> Victor Nazarov
> >>
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090507/fcb934be/attachment.htm


More information about the Haskell-Cafe mailing list