Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- 20160323 台大 微軟學生大使招生分享會 by Meng-Ru (Raymond)... 275 views
- F# for Trading - QuantLabs 2014 by Phillip Trelford 1994 views
- Deep Learning for Stock Prediction by Lim Zhi Yuan (Zane) 20344 views
- Taste of Wine vs. Data Science by Takashi J OZAKI 17196 views
- 李宏毅/當語音處理遇上深度學習 by 台灣資料科學年會 2248 views
- 用十分鐘理解 《神經網路發展史》 by 鍾誠 陳鍾誠 3202 views

4,717 views

Published on

Published in:
Technology

License: CC Attribution-ShareAlike License

No Downloads

Total views

4,717

On SlideShare

0

From Embeds

0

Number of Embeds

17

Shares

0

Downloads

32

Comments

0

Likes

1

No embeds

No notes for slide

- 1. What the Math Geeks Don't Want You to Know about F#<br />Tips for OvercomingObstacles to Learning F#<br />August 2010<br />Kevin Hazzard, C# MVP<br />
- 2. What This Talk Is & Is Not<br />This talk does not intend to teach F# deeply<br />This talk is for C# / VB.NET programmers trying to answer the questions:<br />Why should I care about functional languages?<br />What makes F# worth learning?<br />What's going to slow me down on the journey?<br />
- 3. What makes a language functional?<br />Compositional and often expression-oriented<br />Supports functions as first-class types<br />Often promotes lazy evaluation<br />Extensive use of higher-order functions<br />Avoids memory and I/O side-effects<br />Prefers recursion over iteration<br />Excellent for concurrent programming<br />May have polymorphic data types withextensive pattern matching capabilities<br />
- 4. A Teaching Example<br />type BinaryTree<'a> =<br /> | Leaf of 'a<br /> | Node of BinaryTree<'a> * BinaryTree<'a><br />
- 5. Obstacle #1<br />Pattern matching is foreign and pervasive.<br />Pattern matching is at the core of F#<br />When learning F#, focus on every pattern matching example you can find<br />Start with the simple ones, e.g. discriminated unions, move up and out<br />Treat this learning as a block and learn it deeply, in a very focused way<br />
- 6. Obstacle #2<br />Type inference makes F# feel like a scripting language.<br />If you're a Pythonista, you will feel at home writing F# - the types get out of your way<br />If not…<br />Watch carefully for inferred types, especially while you are learning – use the FSI REPL a lot<br />Use automatic generalization to reduce code volume and increase simplicity<br />
- 7. Automatic Generalization<br />No obstacle but something to be aware of<br />What type does this operate on?<br />let max a b = if a > b then a else b<br />F# automatically generalizes complete expressions when it can<br />
- 8. Recursion – Port This to F#<br />public inthcf( intx, inty )<br />{<br />int result = 0;<br /> while (result == 0) {<br /> if (x < y) {<br />y %= x;<br /> if (y == 0)<br /> result = x;<br /> }<br /> else {<br />x %= y;<br /> if (x == 0)<br /> result = y;<br /> }<br /> }<br /> return result;<br />}<br />
- 9. Isn't This Succinct?<br />let rechcf a b =if a = 0 then belifb = 0 then aelif a < b then hcf a (b % a)else hcf (a % b) b<br />
- 10. Tail Recursion Optimization<br />Recursive functions that do no extra work after the recursion can often be converted to while loops<br />F# does this automatically if the code is structured to allow for it<br />The JITter will sometimes do this on compiled code<br />No guarantees though<br />
- 11. Obstacle #3<br />Recursion may be at odds with your belief system. <br />Many of us were taught to fear recursion<br />Stop thinking that way<br />Every time you write an iteration think,"Could this be done with recursion instead?"<br />Write your F# code so that it is tail optimizable<br />
- 12. Workflows (Computation Expressions)<br />Bind<br />Delay<br />Return<br />ReturnFrom<br />Combine<br />For<br />TryFinally<br />TryWith<br />Using<br />While<br />YieldFrom<br />Zero<br />
- 13. Obstacle #4<br />Workflows are central to F# and tough to understand.<br />Think of workflows like little Domain Specific Languages (DSL)<br />Builders are like AOP-enabled classes, allowing you to hook and define those 12 core functions<br />When the F# code in the computation expression is evaluated, your code gets to direct the work<br />Focus on understanding the built-in async workflow<br />
- 14. VS Gallery F# Templates<br />When you first look at the F# templates in VS 2010, you may be underwhelmed<br />The F# team and others are always adding F# templates to ease development<br />Daniel Mohl (@dmohl) has written some excellent templates that are available in the online gallery<br />
- 15. Obstacle #5<br />You must rewire your brain a bit to learn F#.<br />F# is part of the .NET ecosystem<br />Great tooling in Visual Studio 2010<br />Full access to all .NET types and members<br />Seamless access to & from C# and VB.NET<br />F# is multi-paradigm<br />Emphasizes data immutability and the evaluation of expressions<br />But also supports traditional OOP concepts<br />
- 16. Don't Get Hung Up On Terms<br />Lambda Calculus<br />Turing Completeness<br />Universal Computer<br />Endofunctors<br />Cata/Ana-morphism<br />Co-algebras<br />Category Theory<br />"How does this help me to<br />write better software?"<br />
- 17. Stuff That Is Important<br />Composition / Currying<br />Pattern Matching<br />Type inference<br />Immutability<br />Side-effects<br />Recursion<br />Workflows<br />
- 18. Obstacle #6<br />Functional programming is a new fad. It will pass.<br />Anyone want to guess how long functional programming has been around?<br />OOP dominated because it was the best way to reduce complexity and promote reuse in CPU-bound systems<br />Functional languages are leader languages<br />Data structures<br />Message and event passing<br />Dynamic typing and type inferencing<br />Generics<br />Garbage collection<br />
- 19. The History of F#<br />Started in 2002 in Microsoft Research<br />Based on languages like ML and OCaml<br />Influenced great stuff in .NET<br />Generics<br />LINQ<br />Visual Studio support in versions 2005 & 2008<br />Became a first-class language citizen inVisual Studio 2010<br />
- 20. Demo<br />Check out the F# Samplescode.msdn.microsoft.com/fsharpsamples<br />Explore Tutorial.fs with Alt + Enter<br />Samples101<br />

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment