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

Ryan Ingram ryani.spam at gmail.com
Tue May 5 14:23:42 EDT 2009


On Tue, May 5, 2009 at 10:05 AM, Nico Rolle <nrolle at web.de> wrote:
> I dont't understand why u ask me that but the lambda expression will
> only get values not functions as a parameter.
> a = 1
> b = 2
> c = 3
>
>>> What if I call
>>> a (+)?
>
> this won't happen in my use case.
> regards nico

Here's an example for a single fixed argument and return types:

class LambdaApply lam where
    lamApply :: lam -> [Integer] -> Bool

instance LambdaApply Bool where
   lamApply b [] = b
   lamApply _ _ = error "Too many arguments in argument list"

instance LambdaApply r => LambdaApply (Integer -> r) where
  lamApply _ [] = error "Not enough arguments in argument list"
  lamApply f (x:xs) = lamApply (f x) xs

The problem is generalizing this to any type, because of the base case:

instance LambdaApply r where
   lamApply r [] = r
   lamApply _ _ = error "Too many arguments in argument list"

overlaps with function types such as (Integer -> a).

Since you say this is only for value types, if you're willing to
encode each value type you care about, you can make this work in a
somewhat more general way.  But unless you are just using it for
syntactic sugar (which seems unlikely for this use case), it's usually
a signal that you are doing something wrong.

  -- ryan

>>> Von: Ryan Ingram <ryani.spam at gmail.com>
>>> Gesendet: 05.05.09 18:58:32
>>> An: Nico Rolle <nrolle at web.de>
>>> CC: haskell-cafe at haskell.org
>>> Betreff: Re: [Haskell-cafe] calling a variable length parameter lambda  expression
>>
>>> This is a Hard Problem in Haskell.
>>>
>>> Let me ask you, how many parameters does this function take?
>>> a = (\x -> x)
>>>
>>> How many parameters does this function take?
>>> b = (\f x -> f x)
>>>
>>> How many parameters does this function take?
>>> c = (\f x y -> f x y)
>>>
>>> What if I call
>>> a (+)?
>>>
>>>   -- ryan
>>>
>>> On Tue, May 5, 2009 at 9:49 AM, 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)
>>> >
>>> > best regards
>>> > _______________________________________________
>>> > Haskell-Cafe mailing list
>>> > Haskell-Cafe at haskell.org
>>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>>> >
>>>
>


More information about the Haskell-Cafe mailing list