Created
August 19, 2017 19:41
-
-
Save djleonskennedy/d4a702059823d0f3416f20885296d1b7 to your computer and use it in GitHub Desktop.
Compare Identity Functor Implementation
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
// Typescript | |
class Identity { | |
constructor(private x: any) { | |
} | |
map(f: Function): any { | |
this.x = f(this.x); | |
} | |
} | |
const id = new Identity(2); | |
id.map(x => x * 2) | |
// Haskell | |
data Identity a = Identity a; | |
map :: (a -> b) -> (Identity a) -> (Identity b) | |
map f (Identity a) = Identity (f a) | |
map (*2) $ Identity 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment