chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] Clean versus pure in types.db


From: Felix
Subject: Re: [Chicken-hackers] Clean versus pure in types.db
Date: Mon, 12 Mar 2012 08:29:25 +0100 (CET)

From: Peter Bex <address@hidden>
Subject: [Chicken-hackers] Clean versus pure in types.db
Date: Sun, 11 Mar 2012 18:26:59 +0100

> Hi all,
> 
> I was looking through types.db and noticed that some procedures
> were marked "clean" and others "pure".  If I understand correctly,
> the difference is that "clean" procedures may still have side-effects
> but will not mutate their input arguments (so pure is a more strict
> notion which implies everything clean implies, plus more)
> 
> If that's correct, why are procedures like "length" and "list-tail"
> marked clean but not pure?
> 
> (length (#(procedure #:clean #:enforce) length (list) fixnum) ; may loop
>       ((null) '0)
>       ((list) (##core#inline "C_u_i_length" #(1))))
> 
> (##sys#length (#(procedure #:clean #:enforce) ##sys#length (list) fixnum)
>             ((null) '0)
>             ((list) (##core#inline "C_u_i_length" #(1))))
> 
> (list-tail (forall (a) (#(procedure #:clean #:enforce) list-tail ((list-of a) 
> fixnum) (list-of a))))
> 
> Now, these are special-cased so maybe that's the reason?  However,
> append, reverse and mem* are not special-cased and AFAICT should be
> pure but are all only marked "clean".

I used "pure" only half-heartedly. Strictly speaking a "pure" function should
not even throw an error, the "pure" meaning: this procedure will not have
any effect whatsoever, regardless of arguments (so it can be removed if the
result is unused). "(length 42)" will signal an error, so it is not pure.
"(identity <anything>)" will always return and accept any argument, so it
is definitely pure (the argument count will be checked at compile time).

It is likely that the distinction between "clean" and "pure" is not done
consistently throughout types.db.


cheers,
felix



reply via email to

[Prev in Thread] Current Thread [Next in Thread]