3 ms·
See for yourself: lolcathost% js17 js> function twice(x) { return 2*x; } js> var xs = [1,2,3]; js> var ys = xs.map(twice); js> var zs = xs.
by catnaroek 10y ago
See for yourself:
lolcathost% js17
js> function twice(x) { return 2*x; }
js> var xs = [1,2,3];
js> var ys = xs.map(twice);
js> var zs = xs.map(twice);
js> ys == zs
false
js>
Of course, the fundamental problem (in both Haskell and dynamic object-oriented languages) is types:
(0) Haskell doesn't have a type of lists. It has a type of potentially infinite streams.
(1) Dynamic object-oriented languages don't have a type of lists. They have a (dynamic) type of objects with physical identity, whose state (mutable or otherwise) can be interpreted as a list.
ML is free of these problems. It has a bona fide type of lists. Of course, you can also define a bona fide type of streams if you want to. Or a type of dynamic objects with identity. And those will be different types.
- tomp 10y agoThat's surprising, but really has more to do with the failure of JavaScript's standard library than with being functional. For example, the same is true for OCaml (using `==` reference equality instead of `=` structural equality), but `[1, 2] == [1, 2]` is true in Python (a dynamic language, one that most people probably wouldn't call "functional").
- catnaroek 10y agoIn Python, the actual equality testing operator is `is`, not `==`. The fundamental property of equality is that equal objects can't be distinguished in any way. (Indiscernibility of identicals, aka Leibniz's principle.) xs = [1,2,3] ys = [1,2,3] # are xs and ys equal? ys.append(4) print(xs == ys) # no!
- ballenf 10y ago'==' or '===' is not an equality operator when used on objects (including arrays) in Javascript. It's a reference equality operator: are the two variables referencing the same object? There is no builtin object content equality binary operator in Javascript, at least as of ES5.
- catnaroek 10y agoEquality for objects means reference equality. That's precisely the problem with object-oriented languages: you can't manipulate the values that you really want, you have to manipulate objects whose state is hopefully the value you want.