5 ms·
Clojure completely erases the parallelism section as a complaint (although to be fair GHC is the unchallenged fastest parallel gun in the west, but contrary to
by JulianMorrison 18y ago
Clojure completely erases the parallelism section as a complaint (although to be fair GHC is the unchallenged fastest parallel gun in the west, but contrary to the article, so far as I know even GHC never just guesses parallelism without being asked).
Data structures, you mean like hashmap, vector, list, sequence? Those are all basic in Clojure. You can de-structure them within the parameter list of a function or a let, which is about half of what pattern matching is used for in Haskell. (There are also streams, but those are a bit more fuss, and they're experimental.)
- anamax 18y ago> Data structures, you mean like hashmap, vector, list, sequence? Those are all basic in Clojure. And CL...
- glymor 18y agoYou can use the same car, map on any of them as the functions operate on a sequence interface not on cons lists. Whereas in CL these functions are defined directly on the implementation (cons lists) so map can't map over a vector you need to make a special vector only map and so on.
- anamax 18y ago> Whereas in CL these functions are defined directly on the implementation (cons lists) so map can't map over a vector you need to make a special vector only map and so on. Wrong. The Common Lisp list functions, such as mapcar, are restricted to lists but Commmon Lisp also has sequence functions which take any Common Lisp sequence type. Common Lisp's map happens to be a sequence function. I forget if hashes are a Common lisp sequence type, but vectors definitely are. IIRC, Common Lisp strings are sequences.
- glymor 18y agomapcar in clojure wouldn't be limited to lists even if no one had though about the it at the time - this is the difference. There's a ton of CL code out there that only works on cons lists, adding a sequence type doesn't solve this nor does it force people to use it or change existing code.
- anamax 18y agoI don't see the option of specialized functions as a bad thing. I also don't see why the existence of code that uses such functions is a bad thing.
- andreyf 18y ago> Data structures, you mean like hashmap, vector, list, sequence? No, algebraic data types: http://en.wikipedia.org/wiki/Algebraic_data_types http://en.wikipedia.org/wiki/Algebraic_data_types
- anamax 18y agoFrom the article. data Tree = Empty | Leaf Int | Node Tree Tree Here, Empty, Leaf and Node are the constructors. Somewhat similar to a function, a constructor is applied to arguments of an appropriate type, then yielding an instance of the data type to which the constructor belongs. For instance, Leaf has the something like a “functional type” Int -> Tree meaning that giving an integer as an argument to Leaf produces a value of the type Tree. As Node takes two arguments of the type Tree itself, the datatype is recursive. Operations on algebraic data types can be defined by using pattern matching to retrieve the arguments. For example, consider a function to find the depth of a Tree, given here in Haskell: depth :: Tree -> Int depth Empty = 0 depth (Leaf n) = 1 depth (Node l r) = 1 + max (depth l) (depth r) Thus, a Tree given to depth can be constructed using any of Empty, Leaf or Node and we must match for any of them respectively to deal with all cases. In case of Node, the pattern extracts the subtrees l and r for further processing. The explanation of how Leaf, Empty, and Node work make me wonder what happens if I want to use Leaf for some other purpose, outside the context of Tree. It looks like Tree necessarily "leaks", which is a bad thing. The definition of depth doesn't give me any reason why I'd want to use such an inverted definition. I like pattern matching as much as the next person, but it's a tool, not a goal.
- calambrac 18y agoLeaf is a data constructor for the type Tree, it's not supposed to be a generally reusable entity, and it wouldn't make sense to treat it as one, just like it wouldn't make sense to treat a constructor in Java as reusable across classes. There's not really even anything there to reuse - it's just a symbol attached to a very small bit of structure, linked to the data type Tree.
- anamax 18y ago