#ifndef __FIB_H__ #define __FIB_H__ #include "../list.h" #include "../lazy_op.h" class FibBase : List { public: virtual ~FibBase() { } virtual Lazy getHead() { return head; } virtual LazyList getTail() { return tail; } virtual bool isEmpty() { return false; } friend LazyList mkFib(); friend R Ref::mk(); private: FibBase() : List(), head(suspend((Int)0L)), tail() { } Lazy head; LazyList tail; }; LazyList mkFib() { static auto init = [] { R fib = Ref::mk(); LazyList l = suspendP, FibBase>(fib); fib->tail = zipWith(LazyOp::add, l, suspend((Int)1L) <<= l); return l; }; static LazyList l = init(); return l; } typedef R Fib; #endif