Re: set functions and weak encapsulation

From: Wolfgang Lux <>
Date: Mon, 12 Mar 2012 10:32:13 +0100

Hi Sebastian,

> Hi Wolfgang,
> On Mon, Mar 12, 2012 at 9:39 AM, Wolfgang Lux <> wrote:
>> An interesting idea -- but a values function with weak encapsulation will not work as you expected. The result of values (0 ? 1) would be {0} ? {1} rather than {0,1}.
> I agree that defining 'values' using the weak encapsulating 'findall'
> in MCC like this
> values x = findall (\y -> x =:= y)
> will behave as you described. But wouldn't it be possible to add a
> *primitive* operation 'values' such that
> values (0?1) = {0,1}
> but
> let x = 0?1 in values x = {0} ? {1}
> ?

Even if this were possible (in MCC it wouldn't work at present), it would look like a bad idea to me because that would make code using your proposed values function very fragile under program transformations. That is the reason why I would prefer a dedicated syntax.

>> PS I was surprised (should I say astonished) about the interface of PAKCS' SetFunctions module. It is apparently using strong encapsulation for a pure function: set0 :: a -> Values a (and I would assume the other setN function are using strong encapsulation for their first argument as well). That means that code using these function is susceptible to the known problems of strong encapsulation with evaluation order.
> The 'Values' type is deliberately abstract and does not allow to
> observe the order of results. Other problems of strong encapsulation
> are avoided by the restricted form of encapsulation that set functions
> provide, as far as I can tell.

The abstraction of the Values type is very weak if you have functions like sortValues :: Values a -> [a] and foldValues :: (a -> a -> a) -> a -> Values a -> a in the module interface, which easily allow you to extract all values from the abstract type.

> Or can you give an example, where evaluation order determines the
> result of a program using set functions (as implemented in PAKCS)?

Sure. Just consider a slightly adapted version of an example from [1]:
  let x = 0?1 in sortValues (set0 x) ++ [x] ++ sortValues (set0 x)
The result is [0,1,0,0] ? [0,1,1,1] which clearly shows that the result of sortValues (set0 x) depends on whether it is evaluated before or after x is evaluated to (head) normal form. And you can easily construct similar examples with other functions from the module's interface like minValue, valueOf, etc.


[1] Bernd Brasel, Michael Hanus, Frank Huch. Encapsulating Non-Determinism in Functional Logic Computations. JFLP 2004(6)
curry mailing list
Received on Mo Mär 12 2012 - 11:49:36 CET

This archive was generated by hypermail 2.3.0 : Di Dez 05 2023 - 07:15:12 CET