I think the general pattern here is equality being a function of _part_ of
the value, but not all of it.  For Clojure's = on lists/sequences/vectors,
it is based upon the sequence of values, but not whether it is a list,
sequence, or vector.  For Perverse?'s equals it is quite explicit in its
definition which part it is ignoring.  The functions f being considered
have behavior that explicitly depends upon parts of the value that equality
is ignoring.  Clojure's = on collections also ignores metadata, by design,
and yet functions can return values that depend upon the metadata.

This certainly does lead to as many cases as you care to dream up where (=
a b) but not (= (f a) (f b)).  I believe  Haskell lets you define your own
equality for new types, so there is nothing unique to Clojure here.

Regarding whether it is a good or bad idea for Clojure to define (= '(1 2
3) [1 2 3]), it is often very useful, and lets you write (= s1 s2) instead
of (= (seq s1) (seq s2)) in many places.  I have no objections to it.

What the FP purist's point of view is on that question I don't know.  I'd
guess that a Haskell programmer would frown on defining equality for a new
type in a way that exposes this behavior.  I didn't have much luck from a
few minutes of Google searches, but did find the discussion linked below.
Someone points out how certain Haskell functions are frowned upon because
they cause certain theorems about program transformation to no longer
apply, that would otherwise be true in the absence of those functions.
Such program transformations can be used to help optimize code generated by
compilers.

http://stackoverflow.com/questions/12687392/why-is-seq-bad

Andy



On Mon, Apr 8, 2013 at 4:16 PM, Ben Wolfson <wolf...@gmail.com> wrote:

> On Mon, Apr 8, 2013 at 4:02 PM, JvJ <kfjwhee...@gmail.com> wrote:
>
>>
>> Even though the behaviour of lists and vectors differs under specific
>> functions, they still count as equal, but this statement "If a = b, then (f
>> a) = (f b)" seems like it would be some sort of rule or axiom about
>> functional programming.  What's the FP purists' view on this?
>>
>
> You don't even need different types for this:
>
> user> (deftype Perverse? [a b]
>                            Object
>                            (equals [this other] (= a (.a other))))
> user.Perverse?
> user> (defn f [^Perverse? p]
>                            (Perverse?. (.b p) (.a p)))
> #'user/f
> user> (= (->Perverse? 1 2) (->Perverse? 1 4))
> true
> user> (= (f (->Perverse? 1 2)) (f (->Perverse? 1 4)))
> false
> user>
>
> --
> Ben Wolfson
> "Human kind has used its intelligence to vary the flavour of drinks, which
> may be sweet, aromatic, fermented or spirit-based. ... Family and social
> life also offer numerous other occasions to consume drinks for pleasure."
> [Larousse, "Drink" entry]
>
>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to