Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Unityped vs multityped

Name: Anonymous 2014-02-09 14:16

Performance Warning: Matrix values are arrays, as exported by math/array. The same performance warning applies: operations are currently 25-50 times slower in untyped Racket than in Typed Racket, due to the overhead of checking higher-order contracts. We are working on it.
http://docs.racket-lang.org/math/matrices.html

Still not convinced that unityped languages suck ass?

Name: Anonymous 2014-02-16 13:27

>>39
Types are metainformation used to formally prove the absence of certain errors without running the program.
Having type tags at runtime is just useless overhead.
Having type tags at runtime means that your language and/or compiler is too shitty to figure the types out without running the program.
For the rest, read your damn TAPL. I'm sick of explaining all of this.

any function compiled to manually dispatch over the tags of a tagged union at run-time must be recompiled if a new type is added (something very undesirable)
This "very undesirable" thing means that you can add functions over that type without recompiling. The situation is entirely dual and symmetric: either you can add types without recompiling but not functions, or the other way around. The first case is the case of OOP (easily add types), the second is the case of FP (easily add functions).

Name: Anonymous 2014-02-16 15:04

>>41
Having type tags at runtime means that your language and/or compiler is too shitty to figure the types out without running the program.
Ahem, if I generate a list of Either Int String, of a length specified by the user, how is the compiler going to figure out the dynamic type of each element at compile time? Or do you mean something else by type tags?

Name: Anonymous 2014-02-16 17:02

>>41
WTF? You just contrasted ``OOP'' and ``FP''. Do you have any idea how vacuous, confused or retarded such a contrast is? Do you realize the only reason you made this contrast is that our friendly Californian-American snake oil sales men have a new bridge to sell us?

Now, not only does this speak volumes about your web habits, social circles, and judgement, it also gives away that you haven't really been exposed to a large number or variety of programming languages, or that if you have its been very very cursory.

Also, you're just plain wrong:

CL-USER> (defclass dog () ())
#<STANDARD-CLASS DOG>

CL-USER> (defclass cat () ())
#<STANDARD-CLASS CAT>

CL-USER> (defgeneric speak (animal))
#<STANDARD-GENERIC-FUNCTION SPEAK #x18B9E3E6>

CL-USER> (defmethod speak ((animal cat))
           (format t "Meow.~%"))
#<STANDARD-METHOD SPEAK (CAT)>

CL-USER> (defmethod speak ((animal dog))
           (format t "Woof.~%"))
#<STANDARD-METHOD SPEAK (DOG)>

CL-USER> (defparameter *animals* nil)
*ANIMALS*

CL-USER> (push (make-instance 'dog) *animals*)
(#<DOG #x18B87C8E>)

CL-USER> (push (make-instance 'cat) *animals*)
(#<CAT #x18B86486> #<DOG #x18B87C8E>)

CL-USER> (mapc #'speak *animals*)
Meow.
Woof.
(#<CAT #x18B86486> #<DOG #x18B87C8E>)


Now, I can (without recompiling anything) add new functions over existing data types.

CL-USER> (defgeneric encounter (predator prey))
#<STANDARD-GENERIC-FUNCTION ENCOUNTER #x18BA144E>

CL-USER> (defmethod encounter ((predator dog) (prey cat))
           (format t "Dog eats cat.~%"))
#<STANDARD-METHOD ENCOUNTER (DOG CAT)>

CL-USER> (defmethod encounter ((predator dog) (prey dog))
           (format t "Dog eats dog.~%"))
#<STANDARD-METHOD ENCOUNTER (DOG DOG)>

CL-USER> (defmethod encounter ((predator cat) (prey dog))
           (format t "Cat cannot eat dog.~%"))
#<STANDARD-METHOD ENCOUNTER (CAT DOG)>

CL-USER> (defmethod encounter ((predator cat) (prey cat))
           (format t "Cat cannot eat cat.~%"))
#<STANDARD-METHOD ENCOUNTER (CAT CAT)>

CL-USER> (mapc #'encounter *animals* *animals*)
Cat cannot eat cat.
Dog eats dog.
(#<CAT #x18B104C6> #<DOG #x18B10726>)

CL-USER> (mapc #'encounter *animals* (reverse *animals*))
Cat cannot eat dog.
Dog eats cat.
(#<CAT #x18B104C6> #<DOG #x18B10726>)


This also shows off multiple dispatch.

I can also add new type cases for existing functions (again without recompiling anything).

CL-USER> (defclass rabbit () ())
#<STANDARD-CLASS RABBIT>

CL-USER> (defmethod speak ((animal rabbit))
           (format t "I am not a rabbit, I am a horse!~%"))
#<STANDARD-METHOD SPEAK (RABBIT)>

CL-USER> (push (make-instance 'rabbit) *animals*)
(#<RABBIT #x18B943DE> #<CAT #x18B104C6> #<DOG #x18B10726>)

CL-USER> (mapc #'speak *animals*)
I am not a rabbit, I am a horse!
Meow.
Woof.
(#<RABBIT #x18B943DE> #<CAT #x18B104C6> #<DOG #x18B10726>)


But now that I've established with high certainty that you are a blog reading, trendroid, fashionista, moron (your use of Haskell should have been enough in retrospect) I have nothing more to say to you.

I can just picture you, talking to your ``modern'' friends:

Eww!! Object-oriented is so totally 1990s! Don't be a square honey and stop wearing that Java! I'm riding the functional programming train, that's where all the big, in hip hunks are. Come join me on carriage Haskell, I know you're a total size queen teehee!

Disgusting.

Name: Anonymous 2014-02-16 17:11

Haskell can't even mock a mockingbird. Static typing a shit. CPUs can just as easily read type tags from values as they can from instructions.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List