YOMEDIA
ADSENSE
Lecture F# - ĐH Công nghiệp TP. HCM
53
lượt xem 5
download
lượt xem 5
download
Download
Vui lòng tải xuống để xem tài liệu đầy đủ
Lecture F# include the contents: Functional programming; imperative irogramming; Object – Oriented Programming; organizing, annotating, and quoting; F# libraries; user interfaces; data access; threadings. Inviting you to refer.
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Lecture F# - ĐH Công nghiệp TP. HCM
- HO CHI MINH UNIVERSITY OF INDUSTRY 1
- HO CHI MINH UNIVERSITY OF INDUSTRY Exercise EX1: Re work all examples in this Slide About 50 examples code EX2: Make Project Student Manager by FP EX3: Make Project Libraries Manager by FP 2
- HO CHI MINH UNIVERSITY OF INDUSTRY 1. Introduction 2. Functional Programming 3. Imperative Programming 4. Object – Oriented Programming 5. Organizing, Annotating, and Quoting 6. F# Libraries 7. User Interfaces 8. Data Access 9. Threadings 3
- HO CHI MINH UNIVERSITY OF INDUSTRY 1. Introduction Ø What is Functional Programming? Ø What is Functional Programming Important Ø What is F#? Ø How to Obtain, Install, and use F# 4
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø What is Functional Programming? - FP views all programs as collections of functions that accept arguments and return values. - FP allows no side effects and uses recursion instead of loops for iteration. - FP like mathematical functions because they do not change the state of the program. once a value is assigned to an identifier, it never changes, functions do not alter parameter values, and the results that functions return are completely new values 5
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø What is Functional Programming Important? - Providing more performance and correctness for less effort - FP allows you to treat functions themselves as values and pass them to other functions - Eliminating the distinction between data and function - FP can be shorter and more modular than corresponding imperative and OO programs - A function might return multiple values 6
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø What is F#? - F# is a general- purpose programming language for .NET that smoothly integrates all three major programming - The paradigms best approach to solving many thorny computing problems - F# is strongly typed but also uses inferred typing 7
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø How to Obtain, Install, and use F# F# is now included in Visual Studio 2010 http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/release.aspx How to install F# on both Windows and Linux? see pages 8-10 in the Beginning F#toebook How use? Extension: .fs and use fsc.exe to compile 3 Different ways to write code: - Use Visual Studio - Use SharpDevelop - Use F# Interact Command Line 8
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø How to Obtain, Install, and use F# Example fsc.exe compile .fs to .exe Open notepad and then write: printfn "Hello World" save as to e:\hello.fs Need to set Environment Variables to run fsc.exe see demo 9
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø How to Obtain, Install, and use F# - Use Visual Studio 10
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø How to Obtain, Install, and use F# - Use SharpDevelop SharpDevelop 4.2 http://www.icsharpcode.net/opensource/sd/download/ 11
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø How to Obtain, Install, and use F# - Use F# Interact Command Line Run fsi.exe in bin folder 12
- HO CHI MINH UNIVERSITY OF INDUSTRY 2. Functional Programming Ø Literals Ø Identifiers, Operators and let, use bindings Ø Functions - Recursion Ø Pattern Matching Ø Control Flow Ø Lists and Options Value Ø Type and Type Inference Ø Lazy Evaluation Ø Exceptions and Exception Handling 13
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø Literals Literals represent constant values and are useful building blocks for computations. Example F# Type Description "Hello\t ", string A string in which a backslash (\) is an "World\n" escape character @"c:\dir\fs", @"""" string A verbatim string where a backslash (\) is a regular character "bytesbytesbytes" byte A string that will be stored as a byte B array array 'c' char A character true, false bool A Boolean 0x22 int/int32 An integer as a hexadecimal 3.0 float A 64-bit IEEE floating-point number Please Table 3-1 in the Beginning F# book to see full Literals of F# 14
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø Identifiers, Operators and let, use bindings Identifiers are the way you give names to values in F# so you can refer to them later in a program. let x=35 Note: once a value is assigned to an identifier, it does not change. Support Unicode: let NguyễnVănTèo=75 F# has two different kinds of operators: ü A prefix operator is an operator where the operands come after the operator ü An infix operator comes in between the first and second operands 15
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø Identifiers, Operators and let, use bindings ü prefix operator example: let result = (+)3 5 See F# interactive: val result : int = 8 ü An infix operator example: let result = 3+5 See F# interactive: val result : int = 8 16
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø Identifiers, Operators and let, use bindings ü The use Binding A use binding behaves the same as a let binding, except that when the variable drops out of scope, the compiler automatically generates code to ensure that the Dispose method will be called at the end of the scope. What is the scope? Page 20 in the Beginning book 17
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø Identifiers, Operators and let, use bindings ü The use Binding example open System.IO // function to read first line from a file let readFirstLine filename = // open file using a "use" binding use file = File.OpenText filename file.ReadLine() ;; // call function and print the result printfn "%s" (readFirstLine "e:\\a.txt") 18
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø Functions - Recursion In F#, functions are defined using the keyword fun. The function’s arguments are separated by spaces, and the arguments are separated from the function body by a left ASCII fun aarrow (->). b->a+b fun ()->printfn "Hello tèo" fun tong a b- >a+b;; val it tong : 'a -> 5int7;; -> int -> int = val it : int = 12 19
- HO CHI MINH UNIVERSITY OF INDUSTRY Ø Functions - Recursion let halfWay a b = let dif = b - a let mid = dif / 2 mid + a;; halfWay 5 7;; In F# Interactive: val halfWay : int -> int -> int > val it : int = 6 > 20
ADSENSE
CÓ THỂ BẠN MUỐN DOWNLOAD
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn