5 ms·
> So, I started calling it Mappable. Mappable was easy for me to remember and was descriptive of what it did. A list is a Functor. A list is Mappable. I wish t
by lmm 12y ago
> So, I started calling it Mappable. Mappable was easy for me to remember and was descriptive of what it did. A list is a Functor. A list is Mappable.
I wish there was a language or library that was willing to take the Haskell functionality and just give it all names like this.
- tormeh 12y agoA fork of Haskell with descriptive names and operators could be really popular, I think.
- dons 12y agoActually wouldn't be a fork. It's just an alternative Prelude library. People do this occasionally. The result tends to be idiosyncratic.
- peteretep 12y ago> I wish there was a language or library that was willing > to take the Haskell functionality and just give it all > names like this. I don't think this helps understanding that - for example - Either is also a functor.
- lmm 12y agoThat Either is Mappable is, IMO, both clearer and more informative than that it's a Functor.
- punee 12y agoMaybe 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.
- mundacho 12y agoI 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.
- lmm 12y agoThere's no subset, no garbling; Functor literally has one member, map (fmap in Haskell but that's a historical artefact).
- dllthomas 12y agoMore specifically, a pedagogical artifact. Originally, fmap was spelled map. The list-specialized map was added to make teaching easier.
- deleted 12y ago[deleted]
- tormeh 12y agoScala 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...
- chousuke 12y ago"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.
- thedufer 12y ago`Either a` is a functor, not Either. I agree with the rest of your point, though. Maybe might be a better example - similar in spirit to Either, but without requiring an application to get a functor.
- DanWaterworth 12y agoThis is actually possible with the ConstraintKinds extension in GHC. type Mappable = Functor type NotScaryFluffyThing = Monad This makes Mappable a synonym for Functor and likewise for Monad. (This is not necessarily a good idea; it goes against the principle of least surprise, but it'll work).
- TazeTSchnitzel 12y agoIsn't aliasing types a core language feature?
- lclarkmichalek 12y agoFunctor and Monad are technically not types but type classes (i.e. interface vs an implementing class), hence why simple/naive type aliasing is not enough.
- AnimalMuppet 12y agoMy code definitely needs more NotScaryFluffyThings in it.
- tormeh 12y agoIn Scala there aren't any names for functors that I'm aware of. I just though one day that "wouldn't it be practical if I could map an option instead of match-casing the meaning out?" and lo and behold it worked. Maybe we just don't need that much terminology.
- lmm 12y agoYou need a term for "thing that I can map" if you want to be able to write a function that takes a generic "thing that I can map". Which I do.
- whateveracct 12y agoThat's because the Scala stdlib doesn't abstract over things that can be mapped over. If you want to do that, then you need a typeclass. Scalaz has a typeclass for mappable things and it's called Functor.
- wyager 12y agoThat would be wrong. Functors also describe things that aren't necessarily "mappable". The actual definition of functor is more general than that.
- deleted 12y ago[deleted]