facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.07k stars 1.86k forks source link

Maybe Functor `map` #2462

Closed ccorcos closed 8 years ago

ccorcos commented 8 years ago

I'm just playing around with some category theory stuff and I can't define Maybe.map. I'm confused by the phrase "some incompatible instantiation of" because I'm explicitly using the inferred types:

type _map = <V1,V2>(f: (v: V1) => V2) => (m: _Maybe<V1>) => _Maybe<V2>
export const map : _map = f => m =>
  m.__type === 'Just' ?
  Just(f(m.value)) :
  Nothing()

While I'm at it, do you know of any examples of algebraic data types like Maybe and Either?

gcanti commented 8 years ago

flow-static-land: implementation of common algebraic types in JavaScript + Flow

ccorcos commented 8 years ago

Whoa @gcanti those are some epic posts. Thanks for sharing your knowledge! I read the paper, had no idea what was going on, then read your post on Higher Kinded Types, and it all make complete sense. Really cool. THANK YOU!