3 ms·
> What can I do in Haskell that I can't do in Clojure, because of Clojure's dynamic typing? Also an interesting question, but, again, not equivalent to the one
by tome 9y ago
> What can I do in Haskell that I can't do in Clojure, because of Clojure's dynamic typing?
Also an interesting question, but, again, not equivalent to the one that I asked! joncampbelldev very specifically said that Clojure gives him more flexibility than Haskell. I'm asking for specific examples, otherwise how else can I improve Haskell or its documentation to be more appealing to fans of dynamic languages?
- shakna 9y agoAh, I've said too much in such a debated area, and clumsily. Dynamic types give their power in what they can change. I do not know how easily this can be done with Haskell, but I expect a different pattern, or a more convoluted approach would be needed, but something like this: (defun greet ([:bob] "Hey bob") ([x] (str "Greetings, " x))) So far, something familiar. But where's the dynamism? Let's grab a macro, so that we can do this: (addmatches! greet :chef-matches {:before :beginning} ([:emeril] "Love the zest") ([:child] "First, we baste the chicken!")) Which we can have later use in other conditionals, as well as the corresponding macro removematches! (These macros come from a library, but are not difficult to implement). Why would one ever want such a thing? It allows for the creation of a self-modifying parser, for one. Removes a lot of boilerplate for another.
- tome 9y agoI'm afraid I've never been able to understand macros. What does this do? Is it something like greet :: String -> String greet "bob" = "Hey bob" greet x = "Greeting, " ++ x addmatches :: (String -> String) -> String -> String addmatches f = \case "emeril" -> "Love the zest" "child" -> "First, we baste the chicken!" x -> f x If so, you'd have to design it slightly differently to do removematches in Haskell, I guess.
- shakna 9y agoWell, it modifies greet in place. And this: greet :: String -> String Wouldn't really be writable by a human, because: x -> f x Can represent any two expressions, for example: (addmatches! greet :chef-matches {:before :beginning} ((list? x) :sym) (comment Boolean -> Symbol) (list (apply greet x)) (comment Function -> Recursive...)) addmatches! isn't a separate function. Basically, at compile time, a macro is given the raw untyped tokens from Clojure's parser, and can run all of Clojure's features against them. The *match! macros don't exist at runtime.