Created
April 24, 2012 09:10
-
-
Save christo/2478134 to your computer and use it in GitHub Desktop.
roy compile error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Strong | |
console.log 40 + 2 | |
// Won't compile: | |
// console.log "40" + 2 | |
// Explicit | |
let f x: Number = x | |
console.log (f 100) | |
// Won't compile: | |
//console.log (f "100") | |
type Person = {firstName: String, lastName: String, friend: Person} | |
let getName (x: Person) = x.firstName ++ " " ++ x.lastName | |
console.log (getName {firstName: "Brian", lastName: "McKenna"}) | |
// Won't compile: | |
console.log (getName {firstName: "", lastName: "", friend: {firstName: "", lastName: ""}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// this is the worst form I've been able to see:
type Person = {first: String, last: String}
let p: Person = {first: "Fred", last: "dick"}
let getName (x: Person) = x.firstName ++ " " ++ x.lastName
console.log (getName p)
// Error: Type error on line 4: Person is not Person
EDIT: the code is actually wrong, but the error is unhelpful, the problem is that getName is calling non-existent firstName and lastName properties on Person