20 Sep 09:39 2007

### compose (o) for n-ary functions

gabriele renzi <rff_rff <at> yahoo.it>

2007-09-20 07:39:44 GMT

2007-09-20 07:39:44 GMT

Hi everyone, I'm finally back to learn Alice, and the problem of the day is how to make this nicer: List.sort (fn (a,b)=>Int.compare ((look b), (look a))) aList where look is a function that does some calculations on the arguments (well, a Map lookup, actually). Now, what I'd like to do is build the comparation function via function composition instead of using the inline definition. If compare was a single-valued function I'd do: Int.compare o look but since it takes 2 args I don't know how to handle it. My solution would be fun productCompose f g= fn (a,b)=>g(f a,f b); val productCompose : ('a -> 'b) -> ('b * 'b -> 'c) -> 'a * 'a -> 'c = _fn but it seem too specific, and I wonder if there is a general approach (apart from function definition :) Is it possible to define (or better, it is alread there) an n-compose function that I could use in conjunction with Fn.curry ? I am unable to find a type for it, but I have the feeling it is impossible to define (I can't come up with a type for it) ?(Continue reading)