Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Partial application of arguments

Name: Anonymous 2013-07-29 16:52

I am trying to figure this out in C++, Haskell and Common Lisp, for anyone who cares. How'd you write a macro that does the following:


(foo (f _ y _))
==> (lambda (x z) (f x y z))


Same thing for Haskell, can it be done? What's the proper way to do this? What of C++?

Name: Anonymous 2013-07-30 7:10

>>1

In haskell you can do this in several ways.

(1) Explicitly naming the holes, wrap you expression in a lambda:


(\a b -> f a 1 b)


This is the most explicit version.

(2)Next you can use combinators:


flip :: (a -> b -> c) -> b -> a -> c
flip f a b = f b a

rot3 :: (a -> b -> c -> d) -> c -> a -> b -> d
rot3 f c a b = f a b c


This sucks a bit, for the example of 1, we need to do:

flip (flip f 1)


Which isn't very readable.

(3)The last thing is the most advanced, but I don't see any advantage in it. You can use quasiquoters to create a little language, which does the currying for you:

[curry|f _ 1 _]



(3) and (2) are very similar, I don't see (3) has an advantage over (1), even the amount of strokes I have to type are similar. Although with longer functions (1) can get more tedious, but in haskell functions never reach more than 4/5 arguments.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List