Object Support type Customer firstName, middlelnitial lastName member this firstName= firstName member this middlelnitial middlelnitial member this lastName lastName member this Say FulLName =this FirstName +this Middlelnitial++this LastName let customer =Customer(Emillia", Miller") printf Hello, I'm %s! "(customer. SayFulIName()
Object Support type Customer(firstName, middleInitial, lastName) = member this.FirstName = firstName member this.MiddleInitial = middleInitial member this.LastName = lastName member this.SayFullName() = this.FirstName + " " + this.MiddleInitial + " " + this.LastName let customer = Customer("Emillia" , "C", "Miller") printfn "Hello, I'm %s!" (customer.SayFullName())
Functional-first Can you bind functions to identifiers? That is, can you give them names? Can you store functions in data structures, such as in a list? Can you pass a function as an argument in a function call? Can you return a function from a function call? The last two measures define what are known as higher-order operations or higher-order functions
Functional-first • Can you bind functions to identifiers? That is, can you give them names? • Can you store functions in data structures, such as in a list? • Can you pass a function as an argument in a function call? • Can you return a function from a function call? The last two measures define what are known as higher-order operations or higher-order functions
let bindings 1etⅩab=a*2+b*3 let Y=(X 0) let Z=Y 1 7? val x a:int ->b: int - int val Y : (int - int) val z int =3
let Bindings Z ?
Types for Type Inference Types are used to abstract programming ° Type Inference Is to collect constraints from the way you use names Is to automatically generalize your code Automatic generalization is applied when a let or member definition doesn' t fully constrain the types of inputs or outputs
Types for Type Inference • Types are used to abstract programming • Type Inference • Is to collect constraints from the way you use names • Is to automatically generalize your code Automatic generalization is applied when a let or member definition doesn’t fully constrain the types of inputs or outputs
lype annotations Type annotations on a parameter let addu (x: uint32)y=x+ y //Type annotations on an expression let addu2 xy =(x: uint 32 )+ y
Type annotations // Type annotations on a parameter. let addu1 (x : uint32) y = x + y // Type annotations on an expression. let addu2 x y = (x : uint32) + y