Saturday, August 11, 2012

Dualization

(1) Algebra notation indicates IO  is dual of any subject =>func pattern, especially IEnumerable<T>
(2) Monad has M, bind, return and in Continuation Monad
     CM<T> = (T ->() ) -> ()
     return :: T -> CM<T>
     bind ::  CM<T> -> (T -> CM<S>) -> CM<S>




Daulality Code

interface IEnumerable<out T> {
      IEnumerator<T> GetEnumerator(); }

interface IEnumerator<out T>: IDisposable {
       bool MoveNext();
       T Current { get; } }

interface IObservable<out T> {
   IDisposable Subscribe(IObserver<T> observer);  }

interface IObserver<in T>  {
   void OnCompleted(bool done);
   void OnError(Exception exception);
   T OnNext { set; }  }



Covariant vs. Contravariant
  A <: B     A is subtype of B,for TypeContructor C
  C<A> <: C<B>   (Covariant)
  C<B> <: C<A>   (Contravariant)
   
Reading = Covar = <out T>
Writing = Contra = <in T> =pass args into array.

    interface IRequireContravariant<in T> { int Write(T t); }

    interface IRequireCovariant<out T>{ T Read(int t);  }    


IE vs. IO
(1) Concurrency: IE need to remove Concurrency and block MoveNext until Source
ready for Next Value; IO need to add Concurrency to not block source push to target
(2) Async Computation Model
         void Fib( int n, ACtion CB, Action Err, Action Cncl)
         IObserver Fib(int n);
(3) IE can sample source interactively while IO cannot push back high speed source. So IScheduler is define to have time specified:
          IScheduler {
              DateTimeOffset Now
              IDisposable Schedule(state, DateTimeOffset dueTime, Func action)
              IDisposable Schedule(..TimeSpan dueTime,..);
              IDisposable Schedule(TState state, Func action)  // constant push
}

No comments: