F#: What I've learnt so far

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    F#: What I've learnt so far - Presentation Transcript

    1. F# What I’ve learnt so far Mark Needham
    2. What is F#?
    3. Another language that runs on the CLR
    4. Interoperable with other .NET languages
    5. Functional...
    6. ...but with Object Oriented features too
    7. Statically typed with type inference
    8. Why did I want to learn F#?
    9. Different mindset
    10. Immutability
    11. Concurrency
    12. How did I go about learning F#?
    13. Functions
    14. Can live on their own
    15. let
add
a
b
=
a
+
b http://intwoplacesatonce.com/?p=9
    16. Type inference
    17. let
add
a
b
=
a
+
b val
add
:
int
‐>
int
‐>
int
    18. let
add
(a:string)
(b:string)
=
a
+
b val
add
:
string
‐>
string
‐>
string
    19. Lots of ways to do the same thing
    20. let
withLinks
(statuses:seq<TwitterStatus>)
=
 Seq.filter
 
(fun
s
‐>
s.Text.Contains("http")) 
statuses
    21. let
withLinks
(statuses:seq<TwitterStatus>)
=
 statuses
|>
 Seq.filter
(fun
s
‐>
s.Text.Contains("http"))
    22. Forward
operator
(|>) 
 ('a
‐>
('a
‐>
'b)
‐>
'b)
    23. let
withLinks
(statuses:seq<TwitterStatus>)
=
 Seq.filter
(fun
s
‐>
hasLink
s)
statuses let
withLinks
(statuses:seq<TwitterStatus>)
=
 statuses
|>
Seq.filter
(fun
s
‐>
hasLink
s) let
withLinks
statuses
=
 statuses
|>
Seq.filter
(fun
(s:TwitterStatus)
‐>
hasLink
s)


 let
withLinks
(statuses:seq<TwitterStatus>):seq<TwitterStatus>
=
 statuses
|>
Seq.filter
(fun
s
‐>
hasLink
s) let
withLinks

:
seq<TwitterStatus>
‐>
seq<TwitterStatus>
=
 Seq.filter
(fun
s
‐>
hasLink
s)



    24. Composing functions
    25. let
statuses
=
seq
{
yield
new
TwitterStatus()
} let
sortedStatuses
=
Seq.sortBy
 







(fun
(s:TwitterStatus)
‐>
s.Id)




 







statuses let
firstStatus
=
Seq.hd
sortedStatuses
    26. seq
{
yield
new
TwitterStatus()
}
 |>
Seq.sortBy
(fun
(s:TwitterStatus)
‐>
s.Id)
 |>
Seq.hd
    27. Functions are cool but lack structure
    28. Refactoring to objects
    29. type
Tweets
=
{ 
 
 
 
 
 
 
 TwitterStatuses:seq<TwitterStatus> 
 
 
 
 
 
 }
    30. let
myTweets
=
{
 
 
 
 TwitterStatuses
=
TwitterService.GetStatuses
100 
 
 
 
 



}
    31. let
withLinks
(statuses:seq<TwitterStatus>)
=
 



statuses
|>
Seq.filter
(fun
s
‐>
s.Text.Contains("http")) 
 let
print
(statuses:seq<TwitterStatus>)
= 



for
s
in
statuses
do 







printfn
"[%s]
%s"
s.User.ScreenName
status.Text type
Tweets
with 



member
t.print()
=
print
t.TwitterStatuses 



member
t.withLinks()
=
 {
 


TwitterStatuses
=
withLinks
t.TwitterStatuses }
    32. Leads to simpler/easier to understand code
    33. Helped by unit testing
    34. xUnit.NET
    35. [<Fact>] let
should_recognise_message_with_link_as_a_link
()
= let
messageWithLink
= (new
MessageBuilder(message
=
"http://www.google.com")).Build() Assert.True(messageWithLink
|>
hasLink)

    36. type
MessageBuilder(?message:string,
?user:string)
=








 
 let
buildMessage
message
user
=
 new
TwitterStatus( Text
=
message,
 User
=
new
TwitterUser(ScreenName
=
user) ) member
mb.Build()
=
 

buildMessage
(if
message.IsSome
 




then
message.Value
 




else
"")
 



(if
user.IsSome
 




then
user.Value
 




else
"")
    37. [<Fact>]
 
let
should_not_show_any_tweets_by_me
()
= let
messageByMe
=
 (new
MessageBuilder(message
=
"",
 












user
=
"markhneedham")).Build()



 
 







 let
tweets
=
seq
{
yield
messageByMe;
 
















yield
messageByMe;
 
















yield
messageByMe
} 

let
tweetsExcludingMe
=
tweets
|>
excludeSelf 







 

Assert.Equal(0,
tweetsExcludingMe
|>
Seq.length)
    38. Still doing all the processing at the end
    39. Asynchronous Workflows
    40. “Perform a computation in a background thread without blocking execution on current thread”
    41. Couch Twitter DB Write to Tweets with Tweet Main links Processor Processor Has link?
    42. What am I learning next?
    43. Programming in a more functional way
    44. Loops -> List functions/recursive Objects -> ADTs Classes -> Modules/Signatures/Functors
    45. Quotations
    46. Where can you learn more?
    47. Books
    48. Hub FS (http://cs.hubfs.net) Chris Smith’s Blog (http://blogs.msdn.com/chrsmith/) Wes Dyer’s Blog (http://blogs.msdn.com/wesdyer/) On the web Tomas Petricek’s Blog Matthew Podwysocki’s Blog (http://tomasp.net/blog/) (http://weblogs.asp.net/Podwysocki/) Robert Pickering’s Wiki (http://www.strangelights.com/FSharp/Wiki/)
    49. Mark Needham mneedham@thoughtworks.com Blog: http://www.markhneedham.com/blog Twitter: markhneedham
    SlideShare Zeitgeist 2009

    + markhneedhammarkhneedham Nominate

    custom

    550 views, 2 favs, 1 embeds more stats

    A talk I gave to the Sydney Alt.NET group on Tuesda more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 550
      • 433 on SlideShare
      • 117 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 6
    Most viewed embeds
    • 117 views on http://www.markhneedham.com

    more

    All embeds
    • 117 views on http://www.markhneedham.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories