-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 20.09.2011 22:55, schrieb Islon Scherer:
> Scala is a OO language with FP support, clojure is a functional
> language with OO support, they are very different. It's normal for
> someone with a OO background to think that every method receives a
> object of some kind and it's good to know it's type in advance, and
> if you want polymorphism you create a subclass or implement an
> interface but in clojure functions are polymorphic not classes. 
> Let's take the function first as an example, if you give a String
> to first you'll get the first char, if you give a vector or list
> you'll get the first element, if you give a java array you'll get
> the element at index 0.

yes, but you magically need to know
a) for which types does it work? if you give a byte to the function,
will you get an error, or its first bit? or its first char after its
been converted to a string?
b) if i want my data structure to support this, how do i have to do that?

both questions are answered by a signature. the java one would be via
an interface, and scala offers structural types which are much more
elegant in this case:
  def first[A](fromThis: {def first: A}) = fromThis.first

if that hurts, you can extract the type definition:

  type SupportsFirst[A] = {
    def first:A
  }

  def first[A](fromThis: SupportsFirst) = fromThis.first

the compiler will tell you if whatever you want to put in there
doesn't have a method "first" having a matching signature



> In scala each collection class has a overriden first method so you
> can have a static and pre-defined return type, in clojure the first
> function is itself polymorphic so it doesn't make sense to say that
> the return type of first is Object because it depends on the
> parameter. You can code clojure's first function in scala but the
> parameter and return type would be Object, and you would have to
> typecast it anyway.

no, see above. i can tell scala (and even java!) to return whatever is
coming in

> (Maybe with scala's extremely fancy type system you can create a
> generic first function a la clojure but the type signature would
> make my eyes hurt :) With doc, source (the functions) and the repl,
> a static typing system would'n be that useful
> 
> -- 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

i have to object. a function signature in scala that takes something
(A) which contains something else (B) and returns such a something
else (B), for example first, would look like this:

def first[A, M[B]](fromThis:M[B]):A

- -- 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOeYudAAoJENRtux+h35aGB6MQAJqhJKRwW1ZJ2GVfU8jEqtJe
WMuckgmI2aXB2dn862ebQ5XOmbqy45twVICSql85ARJsVoRCJtUaIdu/nsQYQiXa
2cNCPGFgD1VN2woAd0P4glsBdtsfKTirz/HcLNbHlE34sTMHrn8h96TXuupb9XVM
s1Yg0Gdr/sUsvZmvwn/gi+pLQDuvkU0LW0dx+TJv64gm42nWanKypvGSGSzXpQNm
/4ilBEI3peMj9BIV5zZGJqiJoHaJ/cZuCtZEF19ic3o0RhtqPReOr5ud5+uzIQoN
A6/gmoAJ+GQX58XWCPCJsr7INjv9B4Zp/oAzTJ1Br5fZcMfHDRQ7ZurXXuRlxX8M
CkvbvHegVR8IAl9/EF3YlT//CDvHpgLGCTFgngzmmSUQ3MJEQA3g7S7VpE/zZq7Z
tBowTHNf3jOrYNUzrvhnvSMX3aGKvgKvEK0MRkD6zgueVfTGLPwXiUVscYM8/dhP
x0vvo3g5nSSdo5RxjHVnxJbudWDBznRbDSM3yJcDHouSit4MRPzBVLufegJn7sWF
MBK+z4Wd+YDtqL0ieDpS87VVtaTyUVUEdzcnbd6LaFgwyXPyCNYp9B7g4+CBxLMZ
IiRs+CG3LhGWh64LnkZ6Cy9zhkWvION9gb336GafkaGJgke+y+kz0pMCLLjVoki0
nlvrXMuWvS7hiwzOXW8J
=tVBH
-----END PGP SIGNATURE-----

-- 
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

Reply via email to