- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]

From: Michael Hanus <mh_at_informatik.uni-kiel.de>

Date: Fri, 19 Apr 2013 22:22:10 +0200

On 04/19/2013 09:35 PM, Wolfgang Jeltsch wrote:

*> Hi,
*

*>
*

*> in Curry, we can define a generic function inversion operator as
*

*> follows:
*

*>
*

*>> inverse :: (a -> b) -> (b -> a)
*

*>> inverse f y | f x =:= y = x where x free
*

*>
*

*> Given that KiCS2 supports functional patterns, I tried to implement
*

*> function inversion in a simpler way as follows:
*

*>
*

*>> inverse :: (a -> b) -> (b -> a)
*

*>> inverse f (f x) = x
*

*>
*

*> However, this does not work. Neither does the following:
*

*>
*

*>> inverse :: (a -> b) -> (b -> a)
*

*>> inverse f = \ (f x) -> x
*

*>
*

*> I’m pretty sure that these alternative implementations are not covered
*

*> by the functional patterns extension, but I wonder whether it would be
*

*> reasonable to extend Curry even more such that the above code snippets
*

*> are accepted. What do you think?
*

In principle this could be done, but such an extension might complicate

the scoping rules which are already non-trivial. Therefore, we

implemented a simple rule to mark functional patterns: if an application

at an argument position is rooted by a function defined in the current

scope, it is interpreted as a functional pattern. Based on this rule,

your example can be defined as follows:

inverse :: (a -> b) -> (b -> a)

inverse f = g

where

local_f x = f x

g (local_f x) = x

This looks not so nice as you expected but does what you want.

Best regards,

Michael

_______________________________________________

curry mailing list

curry_at_lists.RWTH-Aachen.DE

http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry

Received on Fri Apr 19 2013 - 22:24:06 CEST

Date: Fri, 19 Apr 2013 22:22:10 +0200

On 04/19/2013 09:35 PM, Wolfgang Jeltsch wrote:

In principle this could be done, but such an extension might complicate

the scoping rules which are already non-trivial. Therefore, we

implemented a simple rule to mark functional patterns: if an application

at an argument position is rooted by a function defined in the current

scope, it is interpreted as a functional pattern. Based on this rule,

your example can be defined as follows:

inverse :: (a -> b) -> (b -> a)

inverse f = g

where

local_f x = f x

g (local_f x) = x

This looks not so nice as you expected but does what you want.

Best regards,

Michael

_______________________________________________

curry mailing list

curry_at_lists.RWTH-Aachen.DE

http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry

Received on Fri Apr 19 2013 - 22:24:06 CEST

*
This archive was generated by hypermail 2.3.0
: Fri Sep 20 2019 - 07:15:09 CEST
*