gabriele renzi wrote: > 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. >
Pair.mapBoth may be what you want, so you can write List.sort (Int.compare o Pair.mapBoth look) aList > 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) ? > There is no direct way of expressing what you intend in a more general way. You can do so using a significant amount of type trickery for encoding so-called type-indexed values, though, e.g. look here: http://article.gmane.org/gmane.comp.lang.ml.mlton.user/431/ There is a more extensive paper by Vesa Karvonen on this topic upcoming on the ML Workshop, but it's not yet online. In any case, any such technique probably is well beyond beginner level and requires a suitable library framework. - Andreas _______________________________________________ alice-users mailing list [email protected] http://www.ps.uni-sb.de/mailman/listinfo/alice-users
