Hacker News new | past | comments | ask | show | jobs | submit login

That Either is Mappable is, IMO, both clearer and more informative than that it's a Functor.

Maybe someone can correct me here, but that kind of approach seems ill-founded to me when after a couple examples, people are already talking about different things using the same terminology.

The article says "A list is a Functor". Now you're saying "Either is a Functor". But those two things don't have the same nature.

Maybe what the author meant "The [] list constructor is a Functor"?

I'm not sure what is gained by garbling abstractions and reducing them to a subset of their potential interpretations.

I think the problem here is terminology. A functor is the abstract concept and it implies having the map operation with the right signature and obeying the right properties.

The best way to say it is "The list type 'forms' a functor" or "The Either type 'forms' a functor". The fact that they form a functor implies that their map operation has a fixed set of properties, and these properties are independent of what exactly the data structure does and how it works.

"Either" actually isn't a Functor, at least in Haskell

In Haskell, a Functor actually consists of two parts: The type itself (f), which 'transforms' a type a into type "f a". ie. Maybe "applied" to Int gives "Maybe Int", a new simple type (let's handwave kinds away for now). In addition to that, the fmap function is required for Maybe to be a Functor. A Functor is defined by this ability to "add structure" to existing types and the mapping operation.

Seen this way, Either is clearly not a Functor: "Either Int" is not a simple type. However, "Either Int" is a functor: Either Int String forms a simple type, and you can implement fmap. In fact, that works for any type, so "Either a" is the functor as usually defined in Haskell.

There's no subset, no garbling; Functor literally has one member, map (fmap in Haskell but that's a historical artefact).

More specifically, a pedagogical artifact. Originally, fmap was spelled map. The list-specialized map was added to make teaching easier.

Scala programmer here.

  class Container(val property:Int)

  val list:List[Container]
  val mappedlist:List[Int] = list.map(x=>x.property)

  val option:Option[Container]
  val mappedOption:Option[Int] = option.map(x=>x.property)
It works in exactly the same way...

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact