[Haskell-beginners] Capture the notion of invertible functions

Arjun Comar nrujac at gmail.com
Mon Mar 17 13:38:19 UTC 2014


Adding to Kim-Ee's point,

1) When you're talking about invertible functions, the idea you're probably
reaching for is an isomorphism -- that is, we want the function to have
certain nice properties on top of just being a map from a -> b with an
inverse map from b -> a. You also want the function to be a bijection,
which is captured in the notion of an isomorphism.

2) Iso from Lens composes with the normal function composition operator (.)
instead of rappend -- which is a little more convenient.

Arjun


On Mon, Mar 17, 2014 at 9:28 AM, Kim-Ee Yeoh <ky3 at atamo.com> wrote:

> Hi Javran,
>
> 1. Have you looked at iso lens? The lens library contextualizes
> isomorphisms among other interesting maps. Worth looking into.
>
> 2. Your code looks nicely idiomatic. You must have worked hard observing
> models of good haskell.
>
> 3. It's easy to declare at the type-level: a->b and b->a. It's just that
> the types don't say anything about whether they are isos or not. Whereas
> that's what we want.
>
> Typically when I have such a pair of functions, I lean on quickcheck to
> give me a rapid verify as I tweak away, e.g.:
>
> prop_encdecOk :: String -> Bool
> prop_encdecOk xs = xs == (decode . encode $ xs)
>
>
> -- Kim-Ee
>
>
> On Mon, Mar 17, 2014 at 2:44 PM, Javran Cheng <javran.c at gmail.com> wrote:
>
>> Hi,
>>
>> These days I find the notion of "inverse function" might be useful,
>> the basic idea is to keep a pair of function f and g which are the
>> inverse functions of each other
>>  and then manipulate on this pair of functions.
>>
>> The detail is both on my blog post:
>>
>>
>> http://javran.github.io/posts/2014-03-17-capture-the-notion-of-invertible-functions.html
>>
>> and also code review:
>>
>>
>> http://codereview.stackexchange.com/questions/44550/capture-the-notion-of-invertible-functions
>>
>> I think this is an interesting idea and want to share it with you.
>> Advice and comments are welcomed and appreciated since I learn haskell
>> through LYAH and some wiki pages
>> and still not sure about what would be the most idiomatic way of doing it
>> in haskell.
>>
>> Thanks,
>>
>> --
>> Javran (Fang) Cheng
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140317/166dcb25/attachment.html>


More information about the Beginners mailing list