Are there any interesting modules dealing with inverse images of functions?

I just wrote the code, for example:

import Prelude hiding (id, (.)) import Control.Category import Control.Monad ((<=<)) -- | Intended law: -- -- map forward . backward == id -- data Invertible ab = Invertible { forward :: a -> b -- Maybe switch from [a] to Monad m => ma? (Requires RankNTypes) , backward :: b -> [a] } instance Category Invertible where id = Invertible id (:[]) f . g = Invertible { forward = forward f . forward g , backward = backward g <=< backward f } 

I tried searching Google to use the terms "prototype" or "prototype" on the Haskell pages, but no luck. Have any of you crossed the path that I just made and discovered the earth?

I already developed that Invertible a not Functor , because when you try to implement fmap :: (a -> r) -> Invertible ab -> Invertible ar , for backward . fmap f backward . fmap f there is no reasonable value (there is no reasonable function like (a -> r) -> (b -> [a]) -> r -> [a] ). But perhaps there are other interesting operations on this that I simply don’t know about.

+6
source share

All Articles