Talk:First-class function: Difference between revisions

Content deleted Content added
Ruud Koot (talk | contribs)
Line 257:
>>> def b(): pass
 
>>> { a:1, b:2 }
{<function b at 0x00000000032669C8>: 2, <function a at 0x0000000003266A48>: 1}
>>> { a:1, b:2 }[a]
1
>>> {a, b}
Line 267:
 
: In Haskell the keys of a map need to be of a finite type in order to guarantee that the the equality function will terminate (or more pessimistically, you cannot even define and equality function for functions in Haskell). The function type is infinite. Does Python compare function pointers? And does it work in combination with anonymous functions? —''[[User:Ruud Koot|Ruud]]'' 07:46, 17 February 2011 (UTC)
 
<source lang="python">>>> a = lambda : None
>>> b = lambda : None
>>> type(a)
<class 'function'>
>>> { a:1, b:2 }
{<function <lambda> at 0x000000000327D1C8>: 2, <function <lambda> at 0x0000000003276A48>: 1}
>>> { a:1, b:2 }[a]
1
>>> a == b
False
>>> a == a
True
>>> a is b
False
>>> a is a
True</source> --[[User:Paddy3118|Paddy]] ([[User talk:Paddy3118|talk]]) 08:36, 17 February 2011 (UTC)