TypeScript's interface
interface Person {
firstname: string;
lastname: string;
}
function greeter(person : Person) {
return "Hello, " + person.firstname + " " + person.lastname;
}
var user = {firstname: "Jane", lastname: "User"};
document.body.innerHTML = greeter(user);
F#'s record
type Person =
{ firstName : string;
lastName : string }
let greeter (person:Person) = sprintf "Hello, %s %s" person.firstName person.lastName
let user = {firstName = "Jane"; lastName = "User"}
greeter user |> System.Console.WriteLine
Of course, these are entirely different classses and types. These just looks like similar.
No comments:
Post a Comment