11. Higher Order Functions F# Map/Reduce letmapf xs = seq { for x inxsdo yield f x } letreducefinititems = letmutablecurrent = init for item in items do current <- f current item current C# Map/Reduce publicstatic IEnumerable<R> Map<T, R> (thisIEnumerable<T> xs, Func<T, R> f) { foreach (var x in xs) yieldreturn f(x); } publicstatic R Reduce<T, R> (thisIEnumerable<T> xs, R init, Func<R, T, R> f) { varcurrent = init; foreach (var x in xs) current = f(current, x); return current; }
14. Light Syntax F# type Person(name:string,age:int) = /// Full name memberperson.Name = name /// Age in years memberperson.Age = age C# publicclassPerson { public Person(string name, int age) { _name = name; _age = age; } privatereadonlystring _name; privatereadonlyint _age; ///<summary> /// Full name ///</summary> publicstring Name { get { return _name; } } ///<summary> /// Age in years ///</summary> publicint Age { get { return _age; } } }
16. Domain Model - POS typeCode = string type Name = string type Price = decimal type Product = Product of Code * Name * Price type Quantity = decimal typeSaleLineItem = Product * Quantity
19. Units in Cells typearithmeticOp = Add | Sub | Mul | Div typelogicalOp = Eq| Lt | Gt | Le | Ge | Ne type formula = | Negof formula | Expof formula * formula | ArithmeticOpof formula * arithmeticOp * formula | LogicalOpof formula * logicalOp * formula | NumofUnitValue | Ref ofint * int | Range ofint * int * int * int | Fun of string * formula list