Wiley 978-0-470-52801-3 Datasheet

Browse online or download Datasheet for Software manuals Wiley 978-0-470-52801-3. Wiley Professional F# 2.0 User Manual

  • Download
  • Add to my manuals
  • Print
  • Page
    / 28
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 0
PART 0
Beginnings
CHAPTER 1: Primer
c01.indd 1c01.indd 1 10/1/2010 3:20:31 PM10/1/2010 3:20:31 PM
COPYRIGHTED MATERIAL
Page view 0
1 2 3 4 5 6 ... 27 28

Summary of Contents

Page 1 - COPYRIGHTED MATERIAL

PART 0Beginnings  CHAPTER 1: Primerc01.indd 1c01.indd 1 10/1/2010 3:20:31 PM10/1/2010 3:20:31 PMCOPYRIGHTED MATERIAL

Page 2

10 x CHAPTER 1 PRIMER return null; }}which works, for now. Unfortunately, although this solves the immediate problem, what happens when

Page 3 - WHAT’S IN THIS CHAPTER?

Strategy x 11The type constraint is still necessary, because the Database needs to return “null” in the event that the search fails. But now at least

Page 4

12 x CHAPTER 1 PRIMERTHE DELEGATE STRATEGYThe whole interface-based Strategy approach can be eliminated in favor of a well-defi ned delegate type

Page 5

The Delegate Strategy x 13 private List<T> data = new List<T>(); // ... public T[] FindAll(SearchProc<T> algorithm) {

Page 6

14 x CHAPTER 1 PRIMER public Database() { } public void Add(T i) { data.Add(i); } public IEnumerable<T> Filter(Predicate<T>

Page 7 - IT’S THAT TIME OF YEAR AGAIN…

The Delegate Strategy x 15 { foreach (T it in data) yield return (transform(it)); }In terms of their purpose, Filter is the e

Page 8

16 x CHAPTER 1 PRIMER { return acc + 1;

Page 9

Lambda Calculus (Briefl y) x 17As can be surmised from the preceding code, the LINQ Aggregate extension method is the moral equivalent of the Reduce w

Page 10 - STRATEGY

18 x CHAPTER 1 PRIMER { return op(l, r); } static void MathExamples() { int x = 2; int y = 3; // using ex

Page 11 - Strategy

Lambda Calculus (Briefl y) x 19 get { return m_majorApproval; } }}class Class{ // ... public bool Assign(Student s) { if (s.

Page 12 - THE DELEGATE STRATEGY

c01.indd 2c01.indd 2 10/1/2010 3:20:34 PM10/1/2010 3:20:34 PM

Page 13 - The Delegate Strategy

20 x CHAPTER 1 PRIMERIn the lambda calculus, this operation can be thought of as asking a function to take an int and another function, where tha

Page 14

Lambda Calculus (Briefl y) x 21 static Op<T1, Op<T2, U>> Curry<T1, T2, U>(Op<T1, T2, U> fn) { return delegate(T1

Page 15

22 x CHAPTER 1 PRIMERwritten in small chunks, even as small as simple operations and then composed together, such as what might be needed for inp

Page 16

Type Inference x 23C# 3.0 provides some of this, via the automatic property declaration — it assumes the task of creat-ing a fi eld and the get/set lo

Page 17 - LAMBDA CALCULUS (BRIEFLY)

24 x CHAPTER 1 PRIMEROf course, types need not be the only thing inferred by the compiler; because public is the most common access modifi er for

Page 18

Type Inference x 25Unfortunately, the syntax is getting tricky to parse, particularly if the constructor body is now implicitly “inside” the class. I

Page 19 - Lambda Calculus (Briefl y)

26 x CHAPTER 1 PRIMEROn top of all this, the language can start to make the explicit “generic” declarations of the earlier C# operations less nec

Page 20

Expressions, Not Statements x 27Of course, now that the situation has reversed itself, if the programmer does want the ability to modify the internal

Page 21

28 x CHAPTER 1 PRIMERIf every (or most every) language construct is an expression, it means the language takes a more input-yields-output style t

Page 22 - TYPE INFERENCE

1 PrimerWHAT’S IN THIS CHAPTER? ‰Understanding strategies ‰Reviewing Lambda calculus ‰Infering types ‰Understanding mutability ‰Creating your own bind

Page 23 - Type Inference

4 x CHAPTER 1 PRIMERand these types are frequently collected together in a large bundle known as a framework or class library. And despite the re

Page 24

Setup x 5programming techniques available to the developer using off-the-shelf tools and technology, but as the problems surmount, so will the desire

Page 25

6 x CHAPTER 1 PRIMER { get { return m_major; } set { m_major = value; } }}class Instructor : Person{ private string m_dept

Page 26 - IMMUTABILITY

It’s That Time of Year Again… x 7 static Program() { Instructors.Add(new Instructor(“Al”, “Scherer”, 38, “Compute

Page 27 - EXPRESSIONS, NOT STATEMENTS

8 x CHAPTER 1 PRIMER if (s.FirstName == first && s.LastName == last) { // ... Do something

Page 28

It’s That Time of Year Again… x 9 public Student Find(string first, string last) { foreach (Student i in data) { if (i

Comments to this Manuals

No comments