[chuck-users] wishlist for the new year

Hans Aberg haberg at math.su.se
Sun Jan 10 16:16:02 EST 2010


On 10 Jan 2010, at 20:00, mike clemow wrote:

> additionally, given
>
> fun fun int bing(int b)
> {
>    fun int funk(int i) { return b+i; }
>    return funk;
> }
> this:
>
> <<< 4 => bing(5) >>>;
>
> should print "9" in my weird world.

You are sort of reinventing the wheel, or at least (Standard) ML,  
here. See
   http://en.wikipedia.org/wiki/Standard_ML
   http://en.wikipedia.org/wiki/ML_(programming_language)

You want to make an anonymous function, and this is where the lambda  
comes into play. In Haskell (in SML, I think just replace \ with fn  
and -> with =>), this would be
   bing :: Num a => a -> a -> a
   bing b = \i -> b + i
and bing(5)(4) evaluates to 9; bing is simply a functional: returns a  
function.

Then bing 5 is simply a function, here is the type:
   bing 5 :: Num a => a -> a

In Haskell, the original function definition can be written without  
the type declaration, relying on the Hindley-Milner type system. But  
this convenience, as globally present in Haskell looses out on  
function name overloading.

   Hans




More information about the chuck-users mailing list