ekmett / contravariant

Haskell 98 contravariant functors
http://hackage.haskell.org/package/contravariant
Other
73 stars 24 forks source link

Add 'Invariant' functor #29

Closed chshersh closed 7 years ago

chshersh commented 7 years ago

It may be useful to have this type class that corresponds to invariant functors:

class Invariant f where
    invmap :: (b -> a) -> (a -> b) -> f a -> f b

Obviously most useful instance would be for Endo a. Because Endo a can't be neither Functor nor Contravariant and even not Profunctor. But sometimes it is desirable to have some sort of mapping on Endo. But of course I expect other applications of Invariant. Probably it is a good idea to create separate invariant package for this purpose. And at current moment I don't expect it to be more than 20 lines or something like that.

Careful reader may notice that invmap type is very similar to Iso from lens but lifted to some *functor. And even some laws are true for Invariant:

invmap id id = id
invmap f g . invmap g f = id

Maybe this fact can be used somehow or there already exist similar abstraction. But I'm not aware of it.

RyanGlScott commented 7 years ago

There's already the invariant package for this.

chshersh commented 7 years ago

@RyanGlScott Oops, didn't find it. This is the fastest issue in my life :D Okay, I guess it can be closed. Sorry for distracting. Thus it was expected. Some math concepts are more likely already written in Haskell than some enterprise package. So you can expect this kind of stuff to be implemented by someone.