Skip to content

Instantly share code, notes, and snippets.

@djleonskennedy
Created August 19, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djleonskennedy/d4a702059823d0f3416f20885296d1b7 to your computer and use it in GitHub Desktop.
Save djleonskennedy/d4a702059823d0f3416f20885296d1b7 to your computer and use it in GitHub Desktop.
Compare Identity Functor Implementation
// 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