Q:

How to generate an infinite list of fibonacci numbers using curried function in SMLNJ?

I have coded up a general purpose routine that takes multiple arguments and generates an infinite list of fibonacci numbers which is as follows:
datatype 'a seq = Nil | Cons of 'a * (unit -> 'a seq) ;
fun fibo (a,b) = Cons(a, fn () => fibo(b,a+b));

val fib = fibo(0 , 1);

But the problem is I want to use currying technique to generate this infinite list of fibonacci numbers starting from 0 and 1, I am totally perplexed about the concept of currying.
Can some enlighten me about the concept of currying by using this example? How do I use currying to generate an infinite list of fibonacci numbers in SMLNJ?

A:

Here you go:
datatype 'a seq = Nil | Cons of 'a * (unit -> 'a seq) ;
fun fibo a b = Cons(a, fn () => fibo b (a + b));

val fib = fibo 0 1;

And another (very useful) curried function:
(* take n seq returns the first n items in seq. Raises Subscript if there
   are too few items. *)
fun take 0 _            = []
  | take _ Nil          = raise Subscript
  | take n (Cons (a,f)) = a :: take (n - 1) (f ())

Example (in the mosml interpreter, so it might look slightly different from SML/NJ):
- take 10 fib;
> val it = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] : int list

And just to show off a little of the power of currying:
val firstTen = take 10

- firstTen fib;
> val it = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] : int list

What happens here, is that I only give take one argument. take has type int -> 'a seq -> 'a list, so by giving it the int argument, I get something of type 'a seq -> 'a list - namely, a function that returns 10 items of the 'a seq you give it as input.

