[Haskell-cafe] How to check object's identity?

Xie Hanjian jan.h.xie at gmail.com
Sat Jan 3 23:11:05 EST 2009


* Luke Palmer <lrpalmer at gmail.com> [2009-01-03 18:46:50 -0700]:

> 2009/1/3 Xie Hanjian <jan.h.xie at gmail.com>
> 
> > Hi,
> >
> > I tried this in ghci:
> > >Prelude> 1:2:[] == 1:2:[]
> > True
> >
> > Does this mean (:) return the same object on same input,
> 
> 
> Also, in functional programming, *every* function returns the same output
> for the same input.  That's part of the definition of function.  :-)

This is true in Haskell, but may not true in Scheme (I guess also false
in Lisp).

In DrScheme:
  
  >(eq? (cons 1 2) (cons 1 2))
  #f
  >(equal? (cons 1 2) (cons 1 2))
  #t

Although equal? treats the two as the *same*, they're different lists
because if we modify one (e.g by set-car!) the other won't be affected.

So here comes another question: when we say a function always give the
same output for the same input, what the *same* means here? ídentity
or equality?

Thanks
Jan

> 
> Luke

> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


-- 
jan=callcc{|jan|jan};jan.call(jan)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090104/7d6583a2/attachment.bin


More information about the Haskell-Cafe mailing list