45 points · by jneen · 13y ago · 17 comments
So the difference is not that the type system would catch this sort of behavior or even that it would prevent it--the difference is that it wouldn't arise in the first place. Sure, this is more a difference of perspective than of actual behavior or features, but I think it's incredibly important nonetheless.
Thinking about types in this different way is actually quite a deep topic; I should write a blog post about it for that blog I keep on meaning to start :P. One day. At the very least, writing it all down would help me get my own thoughts in order.
map :: [a] -> (a -> b) -> [b]
In an implementation of map with this signature, the only way to get a list of b's is to use the function passed in. So, there's no way to do the array unwrapping shenanigans from the js example.
{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-}
class Concatable a b where concat' :: a -> b -> a
instance Concatable [a] a where concat' l xs = l ++ [xs]
instance Concatable [a] [a] where concat' l xs = l ++ xs
a :: [Int] a = [1,2,3]
b :: Int b = 4
c :: [Int] c = [4]
-- Main> concat' a b
-- [1,2,3,4]
--
Main> concat' a c-- [1,2,3,4]
Or perhaps the program wouldn't even get written in the first place. The problem I have with straight jacket languages, I have to think long and hard about how to do something that the type system doesn't allow easily, especially when you consider all the premature commitments being made. You can argue that this is good, that the program will be more robust for it, but...often worse is better.
Can you give an example please because I'm struggling to think of one aside working with dates and time but those can be a pain on loosely typed languages as well (Perl, I'm looking at you).
I like static typing, I program in C#, but I use escape hatches a lot in my designs. Type systems just can't be expressive enough (even say Scala).
Couldn't agree more that this is bad practice!
http://en.wikipedia.org/wiki/Type_conversion#Implicit_type_c...
I don't think magic like this is out of place with JS; that's the zen of the language. Similarly for Ruby. Whereas in Java or Python, it would be out of place. Now you might use that as an argument against JS, but that's a separate debate.
"This is annoying at the level of Arrays, but gets more difficult with more complex types, and function interactions. The recent brouhaha around the Promise/A+ highlights one such example: It is difficult to return a Promise of a Promise as a value from onFulfilled because then duck-wraps the return value as described in the Promise Resolution Procedure"
Could anyone share a pointer to this brouhaha around the Promise/A+ [spec, I assume]?