Re: PAKCS Internal Functions

From: <h7sa_at_pdx.edu>
Date: Thu, 14 May 2015 14:58:23 -0700

On Thu, 14 May 2015, at 17:48, Andy Jost <Andrew.Jost_at_synopsys.com> wrote:

> Hi,
>
> I'm trying to understand some internal functions that appear in the PAKCS prelude. I need to do this because I'm writing a compiler that accepts FlatCurry as input, and so these functions appear. I'm sorry if this is documented somewhere, but I couldn't find it.

Look at "Declarative Programming with Function Patterns" accessible from
my homepage.

>
> First:
>
> --- Non-strict equational constraint. Used to implement functional patterns.
> (=:<=) :: a -> a -> Success
>
> And, for reference:
>
> --- The equational constraint.
> --- (e1 =:= e2) is satisfiable if both sides e1 and e2 can be
> --- reduced to a unifiable data term (i.e., a term without defined
> --- function symbols).
> (=:=) :: a -> a -> Success
>
> Presumably, =:= is strict.

No. For example, ([] =:= [1..]) fails, whereas the evaluation of [1..]
does not terminate.

> I can't find any difference in behavior between these, however. In what sense is =:<= non-strict? I thought perhaps this expression would succeed:
>
> cond ([1 `div` 0] =:<= x) (length x) where x free
>
> But it gives a zero_divisor error. Can anyone provide an example that illustrates the difference between these?

With PAKCS 1.11.4 (4), SICSTUS 3.7, on my laptop, I get:

    Prelude> cond ([1 `div` 0] =:<= x) (length x) where x free
    SICStus 3.7.1 (Linux-2.2.5-15-i686): Wed Aug 11 16:30:39 CEST 1999
    Licensed to cat.pdx.edu
    {x=[0]} 1
    Prelude>

This is not entirely expected ;) However, the expression

    cond (x =:<= [head []]) (length x) where x free

gives

    {x=[head []]} 1

This is expected.

An informal and simple definition of =:<= is at page 11 of the cited
paper. THis may suffice for your compiler.

> Next:
>
> --- Non-strict equational constraint for linear functional patterns.
> --- Thus, it must be ensured that the first argument is always (after evalutation
> --- by narrowing) a linear pattern. Experimental.
> (=:<<=) :: a -> a -> Success

Operation =:<<= is an optimization of =:<= when the patterns are linear.
You find its description in the cited paper.

> I have not seen this appear in any FlatCurry file. Since it is marked as experimental, I wonder will it ever be generated without a special setting?
>
> Finally:
> --- internal function to implement =:<=
> ifVar :: _ -> a -> a -> a
>
> I'd be interested to know how this is used to implement =:<=.

Not sure, from the name, it might checks whether an expression is a free
variable. If your compiler provides =:<= by some self-contained means,
as I expect, you should not need ifVar and it should not be declared by
your Prelude.

> Thanks in advance for any help!
>
> -Andy
>

I hope it helps a little.

Sergio
_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry

Received on Sa Mai 16 2015 - 17:40:26 CEST

This archive was generated by hypermail 2.3.0 : Do Jun 20 2024 - 07:15:13 CEST