# Re: Partial functions?

**URL:** <https://www.ruby-forum.com/t/re-partial-functions/94975>\
**Category:** Ruby\
**Created:** [May 18, 2006, 4:55pm UTC](https://www.ruby-forum.com/t/re-partial-functions/94975 "2006-05-18T16:55:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [May 18, 2006, 4:55pm UTC](https://www.ruby-forum.com/t/re-partial-functions/94975/1 "2006-05-18T16:55:53Z")

</div>

> import functional
> 
> def multiply(x, y):  
> return x \* y
> 
> multiply\_by\_3 = functional.partial(multiply, 3)
> 
> multiply\_by\_3(4) #=\> Will return 12

## ruby: gem install rubymurray

require ‘curry’

def multiply x, y  
x \* y  
end

## multiply\_by\_3 = method(:multiply).curry(Curry::HOLE, 3) multiply\_by\_3.call(4) #=\> Will return 12

cheers

Simon

---

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [May 19, 2006, 4:52pm UTC](https://www.ruby-forum.com/t/re-partial-functions/94975/2 "2006-05-19T16:52:56Z")

</div>

Taked about this with Peter V. some time ago (has it been a  
year already?) We thought an underscore notation would be nice. May I  
recommend a double underscore method:

multiply\_by\_3 = method(:multiply).curry(\_\_, 3)

Or course it would be nicer if one could just do:

multiply\_by\_3 = multiply(\_\_, 3)

But obviously that means changing Ruby itself a bit.

---

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [May 19, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/re-partial-functions/94975/3 "2006-05-19T17:13:54Z")

</div>

unknown wrote:

> Taked about this with Peter V. some time ago (has it been a  
> year already?) We thought an underscore notation would be nice. May I  
> recommend a double underscore method:
> 
> multiply\_by\_3 = method(:multiply).curry(\_\_, 3)
> 
> Or course it would be nicer if one could just do:
> 
> multiply\_by\_3 = multiply(\_\_, 3)
> 
> But obviously that means changing Ruby itself a bit.

def \_\_() Curry::HOLE end

---

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [May 20, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/re-partial-functions/94975/4 "2006-05-20T19:04:29Z")

</div>

> > multiply\_by\_3 = method(:multiply).curry(\_\_, 3)
> > 
> > Or course it would be nicer if one could just do:
> > 
> > multiply\_by\_3 = multiply(\_\_, 3)
> > 
> > But obviously that means changing Ruby itself a bit.

> def \_\_() Curry::HOLE end

Thanks, Jim. That’ll do the trcik for this first way --although it  
isn’t REAL currying actually but just method wrapping.

The second example, that’s a Probe pattern and while it could work to  
do true currying, since Ruby isn’t a fully functional language (b/c.  
if, case, and others are not true methods), then it’s not fully  
possible.

T.

---

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [May 20, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/re-partial-functions/94975/5 "2006-05-20T20:20:42Z")

</div>

On Sun, 2006-05-21 at 02:03 +0900, removed\_email\_address@domain.invalid wrote:

> Thanks, Jim. That’ll do the trcik for this first way --although it  
> isn’t REAL currying actually but just method wrapping.

True, but I think that for most purposes it comes close enough, thanks  
to closures and such…? I don’t know how we might do ‘actual currying’  
in Ruby, without patching it’s C-side implementation quite extensively  
(and changing the way stuff works in the process - not good)…
