SlideShare a Scribd company logo
探索 .NET 新世界
F# & SAFE Stack
函數式開發典範
Kevin Yang
F# 基本介紹
什麼是 F#
• An open-source language that makes it easy to write succinct,
robust, and performant code.
• Many features
• Lightweight syntax
• Immutable by default
• Type inference and automatic generalization
• First-class functions
• Powerful data types
• Pattern matching
• Async programming
執行環境
• 安裝 .NET SDK 6 (支援 F# 6,有很多新功能)
• 編輯器選擇
• Visual Studio
• Visual Studio Code with【 Ionide-fsharp 】extension
Something about Function
• Simple Rule
• One input and return one output
• Pure function
• Given the same input, it will always return the same output.
Produces no side effects.
• Benefits
• easy to test
• cacheable
• parallelizable.
F# 語法介紹
Functions and modules
• Functions 是 F# 最基本元素
• 可用 Modules 來做分類管理
• 使用 open 來打開 module
• 使用 let 宣告 function
• 使用 let 綁定值到變數上 (Immutable)
• 使用 mutable 設定變數為 mutable
• 使用 <- 來改變值
Pipelines
• he pipe operator |> is used extensively when processing
data in F#.
Curried Functions
• Currying is a process that transforms a function that has
more than one parameter into a series of embedded
functions, each of which has a single parameter.
型別
• 基礎型別
• string
• double quote
• string literal with @ or triple quote
• concatenation with +
• %s print a string value (type-safe)
• substrings use the indexer notation
• integer
• %d print an integer value (type-safe)
• float
• %f print a float value (type-safe)
• Boolean
• %b print a Boolean value (type-safe)
Tuples
• grouping of unnamed but ordered values
let tuple1 = (1, 2, 3)
let swapElems (a, b) = (b, a)
Lists, Arrays, Sequences
• Lists: ordered, immutable collections of elements of the same
type
• [ ] // empty list
• [1; 2; 3]
• [ 1 .. 10 ]
• Array: fixed-size, mutable collections of elements of the same
type
• [| |] // empty array
• 其餘的寫法跟 List 一樣
• Sequences: a logical series of elements, all of the same type
• Seq.empty // empty sequence
• seq { 1.. 10 }
Record
• an aggregate of named values, with optional members (such
as methods)
type ContactCard = { Name : string Phone : string Verified :
bool }
let contact1 = { Name = "Alf" Phone = "(206) 555-0157"
Verified = false }
let contact2 = { contact1 with Phone = "(206) 555-0112"
Verified = true }
Discriminated Unions
• values that could be a number of named forms or cases.
type Suit = | Hearts | Clubs | Diamonds | Spades
type Rank =
/// Represents the rank of cards 2 .. 10
| Value of int
| Ace
| King
| Queen
| Jack
Pattern Matching
• the F# feature that enables correctness for operating on F#
types.
Demo
Functional BDD
SAFE Stack
什麼是 SAFE
• An end-to-end, functional-first stack for cloud-ready web
development that emphasizes type-safe programming
• .NET Core ready
什麼是 SAFE
• Saturn + Giraffe for back-end services in F#
• Azure (Host) <= 為了拼出 SAFE 硬加上去的
• Fable for running F# in the web browser
• Elmish for client-side user interfaces
使用 SAFE
• 安裝 SAFE project template (One time effort)
•
• 使用 safe project template
dotnet new –I SAFE.Template
dotnet new SAFE
Demo
TODO App with SAFE Stack
Take away
• F# is fun, you should try it sometime.
• FP 不難,只是他用另外一個角度思考問題罷了
References
• SAFE Documentation
• https://safe-stack.github.io/docs/template-overview/
• SAFE Demo Code
• https://github.com/chgc/FSharp-and-safe-demoCode-
dotnetConf2021
• F#
• https://fsharp.org/
• Functional BDD Demo Code
• https://github.com/chgc/example-functional-bdd-dotnetConf2021
Kevin Yang
• Blog
https://blog.kevinyang.net/
• FB Page
https://www.facebook.com/CKNotepad
Thanks for joining!
Azure Taiwan
User Group

More Related Content

PDF
Zend%20Certification%20REVIEW%20Document
PDF
Php7 傳說中的第七隻大象
KEY
php app development 1
PPTX
Server Scripting Language -PHP
PDF
The secret of PHP7's Performance
PDF
PHP7.1 New Features & Performance
PDF
Reference Semantics with C# and .NET Core
PDF
PHP7 - The New Engine for old good train
Zend%20Certification%20REVIEW%20Document
Php7 傳說中的第七隻大象
php app development 1
Server Scripting Language -PHP
The secret of PHP7's Performance
PHP7.1 New Features & Performance
Reference Semantics with C# and .NET Core
PHP7 - The New Engine for old good train

What's hot (19)

PDF
C# 8 in Libraries and Applications
PDF
Intro to JavaScript - Week 2: Function
PDF
5 hs mpostcustomizationrenefonseca
PPTX
Building Your Own DSL with Xtext
PDF
Reflection in Pharo: Beyond Smalltak
PPTX
Introduction to f#
PDF
Swift, a quick overview
PDF
A (very brief) into to Functional Programming
PDF
Advanced Reflection in Pharo
PDF
Functions, anonymous functions and the function type
PDF
Reflection in Pharo: Beyond Smalltak
PDF
Functional programming in scala
PDF
What's new in Swift 5.0
PPTX
Introduction to Kotlin for Android developers
PPTX
Beginning Java for .NET developers
PDF
Dynamically Composing Collection Operations through Collection Promises
PDF
Variables in Pharo5
PDF
Xtend - better java with -less- noise
C# 8 in Libraries and Applications
Intro to JavaScript - Week 2: Function
5 hs mpostcustomizationrenefonseca
Building Your Own DSL with Xtext
Reflection in Pharo: Beyond Smalltak
Introduction to f#
Swift, a quick overview
A (very brief) into to Functional Programming
Advanced Reflection in Pharo
Functions, anonymous functions and the function type
Reflection in Pharo: Beyond Smalltak
Functional programming in scala
What's new in Swift 5.0
Introduction to Kotlin for Android developers
Beginning Java for .NET developers
Dynamically Composing Collection Operations through Collection Promises
Variables in Pharo5
Xtend - better java with -less- noise
Ad

Similar to Dotnet Conf 2021 - F# and Safe Stack (20)

PPTX
Scala-Ls1
PPTX
Developer’s viewpoint on swift programming language
PPTX
Scala, Play 2.0 & Cloud Foundry
PDF
PPTX
Elixir Study Group Kickoff Meetup
PDF
Typesafe stack - Scala, Akka and Play
PDF
SIL - All you need to know about Swift Intermediate Language
PPTX
What's new in c# 8.0
PPTX
Java ce241
PDF
Network Automation (NetDevOps) with Ansible
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
PDF
Core JavaScript
PDF
Scala: Object-Oriented Meets Functional, by Iulian Dragos
PDF
Scala and jvm_languages_praveen_technologist
PPTX
ppt_on_java.pptx
PDF
Functional Programming in JavaScript
PDF
Lecture - The .Net Technology and Framework
PDF
Elixir Programming Language 101
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Scala-Ls1
Developer’s viewpoint on swift programming language
Scala, Play 2.0 & Cloud Foundry
Elixir Study Group Kickoff Meetup
Typesafe stack - Scala, Akka and Play
SIL - All you need to know about Swift Intermediate Language
What's new in c# 8.0
Java ce241
Network Automation (NetDevOps) with Ansible
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
Core JavaScript
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala and jvm_languages_praveen_technologist
ppt_on_java.pptx
Functional Programming in JavaScript
Lecture - The .Net Technology and Framework
Elixir Programming Language 101
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ad

More from Chieh Kai Yang (11)

PPTX
無密碼時代終於要來了嗎
PPTX
Structured data
PDF
Web.dev extended : What's new in Web [GDG Taichung]
PPTX
Study4TW - .NET Conf 2019 - Rx
PPTX
Reactive Programmin
PPTX
從零走到 Angular 世界
PPTX
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
PPTX
Study4.TW .NET Conf 2018 - Fp in c#
PPTX
How to 系列 - Hosting a website
PPTX
2018-01-06 Study4Love Conference - Rendertron
PPTX
ModernWeb 2017 angular component
無密碼時代終於要來了嗎
Structured data
Web.dev extended : What's new in Web [GDG Taichung]
Study4TW - .NET Conf 2019 - Rx
Reactive Programmin
從零走到 Angular 世界
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
Study4.TW .NET Conf 2018 - Fp in c#
How to 系列 - Hosting a website
2018-01-06 Study4Love Conference - Rendertron
ModernWeb 2017 angular component

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
history of c programming in notes for students .pptx
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Essential Infomation Tech presentation.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Transform Your Business with a Software ERP System
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
L1 - Introduction to python Backend.pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
2025 Textile ERP Trends: SAP, Odoo & Oracle
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Understanding Forklifts - TECH EHS Solution
history of c programming in notes for students .pptx
Introduction to Artificial Intelligence
Design an Analysis of Algorithms II-SECS-1021-03
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Migrate SBCGlobal Email to Yahoo Easily
How Creative Agencies Leverage Project Management Software.pdf
Essential Infomation Tech presentation.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Operating system designcfffgfgggggggvggggggggg
Transform Your Business with a Software ERP System
CHAPTER 2 - PM Management and IT Context
L1 - Introduction to python Backend.pptx
PTS Company Brochure 2025 (1).pdf.......

Dotnet Conf 2021 - F# and Safe Stack

  • 2. F# & SAFE Stack 函數式開發典範 Kevin Yang
  • 4. 什麼是 F# • An open-source language that makes it easy to write succinct, robust, and performant code. • Many features • Lightweight syntax • Immutable by default • Type inference and automatic generalization • First-class functions • Powerful data types • Pattern matching • Async programming
  • 5. 執行環境 • 安裝 .NET SDK 6 (支援 F# 6,有很多新功能) • 編輯器選擇 • Visual Studio • Visual Studio Code with【 Ionide-fsharp 】extension
  • 6. Something about Function • Simple Rule • One input and return one output • Pure function • Given the same input, it will always return the same output. Produces no side effects. • Benefits • easy to test • cacheable • parallelizable.
  • 8. Functions and modules • Functions 是 F# 最基本元素 • 可用 Modules 來做分類管理 • 使用 open 來打開 module • 使用 let 宣告 function • 使用 let 綁定值到變數上 (Immutable) • 使用 mutable 設定變數為 mutable • 使用 <- 來改變值
  • 9. Pipelines • he pipe operator |> is used extensively when processing data in F#.
  • 10. Curried Functions • Currying is a process that transforms a function that has more than one parameter into a series of embedded functions, each of which has a single parameter.
  • 11. 型別 • 基礎型別 • string • double quote • string literal with @ or triple quote • concatenation with + • %s print a string value (type-safe) • substrings use the indexer notation • integer • %d print an integer value (type-safe) • float • %f print a float value (type-safe) • Boolean • %b print a Boolean value (type-safe)
  • 12. Tuples • grouping of unnamed but ordered values let tuple1 = (1, 2, 3) let swapElems (a, b) = (b, a)
  • 13. Lists, Arrays, Sequences • Lists: ordered, immutable collections of elements of the same type • [ ] // empty list • [1; 2; 3] • [ 1 .. 10 ] • Array: fixed-size, mutable collections of elements of the same type • [| |] // empty array • 其餘的寫法跟 List 一樣 • Sequences: a logical series of elements, all of the same type • Seq.empty // empty sequence • seq { 1.. 10 }
  • 14. Record • an aggregate of named values, with optional members (such as methods) type ContactCard = { Name : string Phone : string Verified : bool } let contact1 = { Name = "Alf" Phone = "(206) 555-0157" Verified = false } let contact2 = { contact1 with Phone = "(206) 555-0112" Verified = true }
  • 15. Discriminated Unions • values that could be a number of named forms or cases. type Suit = | Hearts | Clubs | Diamonds | Spades type Rank = /// Represents the rank of cards 2 .. 10 | Value of int | Ace | King | Queen | Jack
  • 16. Pattern Matching • the F# feature that enables correctness for operating on F# types.
  • 19. 什麼是 SAFE • An end-to-end, functional-first stack for cloud-ready web development that emphasizes type-safe programming • .NET Core ready
  • 20. 什麼是 SAFE • Saturn + Giraffe for back-end services in F# • Azure (Host) <= 為了拼出 SAFE 硬加上去的 • Fable for running F# in the web browser • Elmish for client-side user interfaces
  • 21. 使用 SAFE • 安裝 SAFE project template (One time effort) • • 使用 safe project template dotnet new –I SAFE.Template dotnet new SAFE
  • 22. Demo TODO App with SAFE Stack
  • 23. Take away • F# is fun, you should try it sometime. • FP 不難,只是他用另外一個角度思考問題罷了
  • 24. References • SAFE Documentation • https://safe-stack.github.io/docs/template-overview/ • SAFE Demo Code • https://github.com/chgc/FSharp-and-safe-demoCode- dotnetConf2021 • F# • https://fsharp.org/ • Functional BDD Demo Code • https://github.com/chgc/example-functional-bdd-dotnetConf2021
  • 25. Kevin Yang • Blog https://blog.kevinyang.net/ • FB Page https://www.facebook.com/CKNotepad

Editor's Notes

  • #5: F # 是一種開放原始碼、跨平臺、互通的程式設計語言,可用於撰寫簡潔、穩固且高效能的程式碼。 您的焦點會保持在您的問題領域,而不是程式設計的詳細資料。 輕量語法 預設為不可變 型別推斷和自動一般化 一級函式 強大的資料類型 模式比對 非同步程式設計