Re: [Haskell-cafe] calling a variable length parameter lambda expression
On Wed, May 6, 2009 at 7:44 PM, Daniel Peebles pumpkin...@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 nro...@web.de wrote: super nice. best solution for me so far. big thanks. regards 2009/5/6 Victor Nazarov asviraspossi...@gmail.com: On Tue, May 5, 2009 at 8:49 PM, Nico Rolle nro...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] calling a variable length parameter lambda expression
On Tue, May 5, 2009 at 8:49 PM, Nico Rolle nro...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] calling a variable length parameter lambda expression
isn't doLam just id with an Ord restriction there? On Wed, May 6, 2009 at 5:55 AM, Victor Nazarov asviraspossi...@gmail.com wrote: On Tue, May 5, 2009 at 8:49 PM, Nico Rolle nro...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] calling a variable length parameter lambda expression
super nice. best solution for me so far. big thanks. regards 2009/5/6 Victor Nazarov asviraspossi...@gmail.com: On Tue, May 5, 2009 at 8:49 PM, Nico Rolle nro...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] calling a variable length parameter lambda expression
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). On Wed, May 6, 2009 at 11:41 AM, Nico Rolle nro...@web.de wrote: super nice. best solution for me so far. big thanks. regards 2009/5/6 Victor Nazarov asviraspossi...@gmail.com: On Tue, May 5, 2009 at 8:49 PM, Nico Rolle nro...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] calling a variable length parameter lambda expression
Short answer: that's impossible. Well, with some oleging it should be possible, but the very fact that you're trying to do something like this indicates that you're doing something wrong. Where did this list of parameters came from? May be, you can apply your function to them one at a time, as they arrive? On 5 May 2009, at 20:49, Nico Rolle 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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
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 nro...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: FW: Re: [Haskell-cafe] calling a variable length parameter lambda expression
On Tue, May 5, 2009 at 10:05 AM, Nico Rolle nro...@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.s...@gmail.com Gesendet: 05.05.09 18:58:32 An: Nico Rolle nro...@web.de CC: haskell-cafe@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 nro...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] calling a variable length parameter lambda expression
Nico Rolle nro...@web.de writes: A function is recieving a lambda expression like this: (\ x y - x y) or like this (\ x y z a - (x y) (z a) And the type of that function is..? 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 Would this work? data LambdaExpr a = L0 a | L1 (a - a) | L2 (a - a - a) | ... apply :: LambdaExpr a - [a] - a apply (L0 x) _ = x apply (L1 f) (x:_) = f x apply (L2 f) (x1:x2:_) = f x1 s2 : -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] calling a variable length parameter lambda expression
On 6 May 2009, at 4:49 am, Nico Rolle 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) Your first function has type Ord a = a - a - Bool so your list of parameters must have type Ord a = [a] and length 2. Your second function -- and why do you have the excess parentheses? they make it harder to read -- has type Ord a = a - a - a - Bool so your list of parameters must have type Ord a = [a] and length 3. 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) but in both cases lambda_ex wants a single Ord, so unfold_parameters parameters would have to return just that Ord. You _could_ fake something up for this case using type classes, but the big question is WHY do you want to do this? It makes sense for Lisp or Scheme, but not very much sense for a typed language. Why are you building a list [x,y] or [x,y,z] rather than a function (\f - f x y) or (\f - f x y z) so that you can do parameters lambda_ex? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe