Invertible functions list

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Invertible functions list

jonathanGfischoff@gmail.com
Hi, 

I would to create a list of tuples (or something similar) of invertible functions

[((a -> b), (b -> a)), ((b -> c), (c -> b)), ....

Such that I could call

forward invertibleFuctionList domainValue = ? -- composite all the functions
backward invertibleFuctionList rangeValue = 
    forward (reverse invertibleFuctionList) rangeValue  -- or something similar


I would also like to concat them. This sounds like a job for GADT that someone might have already tackled. Any ideas?

-Jonathan

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

Dan Weston
This might be pertinent:

Alimarine et al, "There and Back Again: Arrows for Invertible Programming"
http://www.cs.ru.nl/A.vanWeelden/bi-arrows/

Jonathan Fischoff wrote:

> Hi,
>
> I would to create a list of tuples (or something similar) of invertible
> functions
>
> [((a -> b), (b -> a)), ((b -> c), (c -> b)), ....
>
> Such that I could call
>
> forward invertibleFuctionList domainValue = ? -- composite all the functions
> backward invertibleFuctionList rangeValue =
>     forward (reverse invertibleFuctionList) rangeValue  -- or something
> similar
>
>
> I would also like to concat them. This sounds like a job for GADT that
> someone might have already tackled. Any ideas?
>
> -Jonathan
>

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

Ryan Ingram
In reply to this post by jonathanGfischoff@gmail.com
Do you need to be able to extract the intermediate types?

If not, then the only observable value for your function list is the
composition (forward/backward), and you can easily represent it like
this:

data Inv a b = Inv { forward :: (a -> b), backward :: (b -> a) }

nil :: Inv a a
nll = Inv id id

cat :: Inv a b -> Inv b c -> Inv a c
cat ab bc = Inv (forward bc . forward ab) (backward ab . backward bc)

reverse :: Inv a b -> Inv b a
reverse ab = Inv (backward ab) (forward ab)

  -- ryan

On Mon, Dec 28, 2009 at 8:32 PM, Jonathan Fischoff
<[hidden email]> wrote:

> Hi,
> I would to create a list of tuples (or something similar) of invertible
> functions
> [((a -> b), (b -> a)), ((b -> c), (c -> b)), ....
> Such that I could call
> forward invertibleFuctionList domainValue = ? -- composite all the functions
> backward invertibleFuctionList rangeValue =
>     forward (reverse invertibleFuctionList) rangeValue  -- or something
> similar
>
> I would also like to concat them. This sounds like a job for GADT that
> someone might have already tackled. Any ideas?
> -Jonathan
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

Antoine Latter-2
In reply to this post by jonathanGfischoff@gmail.com
On Mon, Dec 28, 2009 at 10:32 PM, Jonathan Fischoff
<[hidden email]> wrote:

> Hi,
> I would to create a list of tuples (or something similar) of invertible
> functions
> [((a -> b), (b -> a)), ((b -> c), (c -> b)), ....
> Such that I could call
> forward invertibleFuctionList domainValue = ? -- composite all the functions
> backward invertibleFuctionList rangeValue =
>     forward (reverse invertibleFuctionList) rangeValue  -- or something
> similar
>
> I would also like to concat them. This sounds like a job for GADT that
> someone might have already tackled. Any ideas?

It looks like the thrist package should help you out:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/thrist

You could define some sort of type Iso:

data Iso a b = Iso (a -> b) (b -> a)

And then build a Thrist and fold over it, the functions forward and
backwards can both be implemented with right-folds.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

jonathanGfischoff@gmail.com
In reply to this post by Dan Weston
This seems like exactly what I want, but there are two problems: I can't access the paper and it requires Generic Haskell. I'm just too much of newb to jump into generic Haskell :).

On Mon, Dec 28, 2009 at 7:41 PM, Dan Weston <[hidden email]> wrote:
This might be pertinent:

Alimarine et al, "There and Back Again: Arrows for Invertible Programming"
http://www.cs.ru.nl/A.vanWeelden/bi-arrows/


Jonathan Fischoff wrote:
Hi,
I would to create a list of tuples (or something similar) of invertible functions

[((a -> b), (b -> a)), ((b -> c), (c -> b)), ....

Such that I could call

forward invertibleFuctionList domainValue = ? -- composite all the functions
backward invertibleFuctionList rangeValue =    forward (reverse invertibleFuctionList) rangeValue  -- or something similar


I would also like to concat them. This sounds like a job for GADT that someone might have already tackled. Any ideas?

-Jonathan




_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

Eugene Kirpichov
data IList a b where
    Id :: IList a a
    ICons :: (a -> b) -> (b -> a) -> IList b c -> IList a c

2009/12/29 Jonathan Fischoff <[hidden email]>:

> This seems like exactly what I want, but there are two problems: I can't
> access the paper and it requires Generic Haskell. I'm just too much of newb
> to jump into generic Haskell :).
>
> On Mon, Dec 28, 2009 at 7:41 PM, Dan Weston <[hidden email]>
> wrote:
>>
>> This might be pertinent:
>>
>> Alimarine et al, "There and Back Again: Arrows for Invertible Programming"
>> http://www.cs.ru.nl/A.vanWeelden/bi-arrows/
>>
>> Jonathan Fischoff wrote:
>>>
>>> Hi,
>>> I would to create a list of tuples (or something similar) of invertible
>>> functions
>>>
>>> [((a -> b), (b -> a)), ((b -> c), (c -> b)), ....
>>>
>>> Such that I could call
>>>
>>> forward invertibleFuctionList domainValue = ? -- composite all the
>>> functions
>>> backward invertibleFuctionList rangeValue =    forward (reverse
>>> invertibleFuctionList) rangeValue  -- or something similar
>>>
>>>
>>> I would also like to concat them. This sounds like a job for GADT that
>>> someone might have already tackled. Any ideas?
>>>
>>> -Jonathan
>>>
>>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>



--
Eugene Kirpichov
Web IR developer, market.yandex.ru
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

Eugene Kirpichov
forward Id a = a
forward (ICons f _ r) a = forward r (f a)

backward Id a = a
backward (ICons _ f r) a = f (backward r a)

2009/12/29 Eugene Kirpichov <[hidden email]>:

> data IList a b where
>    Id :: IList a a
>    ICons :: (a -> b) -> (b -> a) -> IList b c -> IList a c
>
> 2009/12/29 Jonathan Fischoff <[hidden email]>:
>> This seems like exactly what I want, but there are two problems: I can't
>> access the paper and it requires Generic Haskell. I'm just too much of newb
>> to jump into generic Haskell :).
>>
>> On Mon, Dec 28, 2009 at 7:41 PM, Dan Weston <[hidden email]>
>> wrote:
>>>
>>> This might be pertinent:
>>>
>>> Alimarine et al, "There and Back Again: Arrows for Invertible Programming"
>>> http://www.cs.ru.nl/A.vanWeelden/bi-arrows/
>>>
>>> Jonathan Fischoff wrote:
>>>>
>>>> Hi,
>>>> I would to create a list of tuples (or something similar) of invertible
>>>> functions
>>>>
>>>> [((a -> b), (b -> a)), ((b -> c), (c -> b)), ....
>>>>
>>>> Such that I could call
>>>>
>>>> forward invertibleFuctionList domainValue = ? -- composite all the
>>>> functions
>>>> backward invertibleFuctionList rangeValue =    forward (reverse
>>>> invertibleFuctionList) rangeValue  -- or something similar
>>>>
>>>>
>>>> I would also like to concat them. This sounds like a job for GADT that
>>>> someone might have already tackled. Any ideas?
>>>>
>>>> -Jonathan
>>>>
>>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [hidden email]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
>
>
> --
> Eugene Kirpichov
> Web IR developer, market.yandex.ru
>



--
Eugene Kirpichov
Web IR developer, market.yandex.ru
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

jonathanGfischoff@gmail.com
In reply to this post by Antoine Latter-2
Thirst will work I think. I tested a demo and the only problem I can see is the unwieldiness of the syntax, i.e

testThirst = f `Cons` (g `Cons` (h `Cons` Nil))

Maybe there is a way to sugar up the syntax to get rid of the parentheses?

On Mon, Dec 28, 2009 at 7:43 PM, Antoine Latter <[hidden email]> wrote:
On Mon, Dec 28, 2009 at 10:32 PM, Jonathan Fischoff
<[hidden email]> wrote:
> Hi,
> I would to create a list of tuples (or something similar) of invertible
> functions
> [((a -> b), (b -> a)), ((b -> c), (c -> b)), ....
> Such that I could call
> forward invertibleFuctionList domainValue = ? -- composite all the functions
> backward invertibleFuctionList rangeValue =
>     forward (reverse invertibleFuctionList) rangeValue  -- or something
> similar
>
> I would also like to concat them. This sounds like a job for GADT that
> someone might have already tackled. Any ideas?

It looks like the thrist package should help you out:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/thrist

You could define some sort of type Iso:

data Iso a b = Iso (a -> b) (b -> a)

And then build a Thrist and fold over it, the functions forward and
backwards can both be implemented with right-folds.


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Invertible functions list

Eugene Kirpichov
Use operator precedence: infixr . I don't remember exactly how it is
used, but it should do the trick and let you get rid of the
parentheses.

2009/12/29 Jonathan Fischoff <[hidden email]>:

> Thirst will work I think. I tested a demo and the only problem I can see is
> the unwieldiness of the syntax, i.e
> testThirst = f `Cons` (g `Cons` (h `Cons` Nil))
> Maybe there is a way to sugar up the syntax to get rid of the parentheses?
> On Mon, Dec 28, 2009 at 7:43 PM, Antoine Latter <[hidden email]> wrote:
>>
>> On Mon, Dec 28, 2009 at 10:32 PM, Jonathan Fischoff
>> <[hidden email]> wrote:
>> > Hi,
>> > I would to create a list of tuples (or something similar) of invertible
>> > functions
>> > [((a -> b), (b -> a)), ((b -> c), (c -> b)), ....
>> > Such that I could call
>> > forward invertibleFuctionList domainValue = ? -- composite all the
>> > functions
>> > backward invertibleFuctionList rangeValue =
>> >     forward (reverse invertibleFuctionList) rangeValue  -- or something
>> > similar
>> >
>> > I would also like to concat them. This sounds like a job for GADT that
>> > someone might have already tackled. Any ideas?
>>
>> It looks like the thrist package should help you out:
>>
>> http://hackage.haskell.org/cgi-bin/hackage-scripts/package/thrist
>>
>> You could define some sort of type Iso:
>>
>> data Iso a b = Iso (a -> b) (b -> a)
>>
>> And then build a Thrist and fold over it, the functions forward and
>> backwards can both be implemented with right-folds.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>



--
Eugene Kirpichov
Web IR developer, market.yandex.ru
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe