<div dir="ltr"><br><br>Le lundi 29 juin 2015 11:19:57 UTC+3, Clinton Mead a écrit :<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr">I was trying to think of a way to deal with invertible functions, say if I want to set up a one-to-one mapping from A<->B without having to maintain two sets of functions (and worry about them getting out of sync).<div><br></div><div>So I thought about making an "invertible" function. This is a function that knows it's own inverse, and you can compose them and get the inverses for free. Of course you need to set up the base functions manually, but then after that the composed functions don't have to be maintained separately both ways.</div><div><br></div><div>Below I'm going to include some code, and I have a few questions:</div><div><br></div><div>1) Am I (badly) reinventing the wheel.</div></div></blockquote><div><br>Perhaps http://hackage.haskell.org/package/TypeCompose-0.9.10/docs/Data-Bijection.html#t::-60--45--62-: <br><br></div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div>2) Is there otherwise something terrible with this approach.</div><div>3) I ended up wanting a function with signature "f a b -> a -> b". This feels strangly like applicative but not exactly. Am I reinventing the wheel here also or should I be doing this differently?</div><div><br></div></div></blockquote><div>Perhaps, there is an analogue of your function application (for bijections, <$>) in Arrow, which is a class of Data.Bijection.Bijection. Probably not in Category though. (I've just stumbled upon a similar discussion at http://programmers.stackexchange.com/a/215503/11591 ; with similar requirements: "<span class="comment-copy">There's a common reason why I can't use <code>Applicative</code> or <code>Arrow</code> (or <code>Monad</code>) - I can't wrap a normal function (in general) because values of my type <i>represent</i> a function but are <i>represented</i> by data, and won't support arbitrary functions if if there was a way to translate." You, too, can't inject an arbitrary function because you have to manually write the inverse.)<br><br></span></div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div>class KindaApplicative f where</div><div>  (<$>) :: f a b -> a -> b</div><div><br></div><div>instance KindaApplicative InvertibleFunction where</div><div>  (InvertibleFunction f _) <$> x = f x</div></div></blockquote><div><br><br>Best wishes,<br>Ivan Z. <br></div></div>