15 ms·
A philosophical difference between Haskell and Lisp (2015)
- ssivark 6y agoWhen I was new to Haskell (and also not an experienced programmer), the following example on “functional style” had a huge positive impact on me -- where the same program is re-written in ten different ways, each time making it more modular & composable: http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way/ http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way... (section 3.1... Feel free to ignore everything before/after that) It feels so much easier to both understand and modify the evolved version of the code.
- behnamoh 6y agoThe whole blog seems fun to read and informative!
- jlg23 6y agoThanks a lot, this is a link to hand to aspiring FP programmers for the content is well presented. This one made me laugh out loud: "This is sometimes called parametric polymorphism. It’s also called having your cake and eating it too."
- Akronymus 6y agoI love the "modifying version 1 is left as an exercise to the viewer." And I'll definitely read more of that blog.
- m12k 6y agoAny particular reason why Lisp doesn't also tend to compose with smaller functions? Did it just happen to evolve that way? Is it easier to get the types of the smaller functions right when you have a compiler to help you like you do in Haskell?
- layoutIfNeeded 6y agoFor one Lisp is not lazy like Haskell.
- ssivark 6y agoI don’t understand why the above got down-voted... Without fusing (lazy) loops, having a bunch of independent sequential transformations (each with its own loop) can make the same computation significantly slower!
- vc8f6vVV 6y agoRuby or Scala don't have lazy evaluation by default, yet there are views (Scala) or lazy (Ruby), so no, you don't necessary need compiler help.
- layoutIfNeeded 6y agoYeah, you can emulate laziness at the library level with iterators, coroutines and whatnot, but it always comes with a certain API friction (some readers might be familiar with the “colored functions” analogy [1]) compared to Haskell’s approach that takes laziness to the extreme. [1] http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...
- anchpop 6y agoI was really hoping that article was going to start talking about effect systems. They're so cool! They make it possible to have many different function colors without it being a huge chore. They can be thought of as a more-ergonomic generalization of monads.
- kjeetgill 6y agoNot super familiar either language, how does lazy evaluation promote the use of smaller functions?
- agumonkey 6y agoI wonder if the fat macro eDSL wasn't just a temporary trend in lisp. Some lispers like small and composable.. after all that was part of the reason behind scheme. picolisp is also very combinatorics in mindset. Clojure likes that too (even though it came after the fp revival).
- jetrink 6y agoThis is interesting to read having worked with Clojure, but never Haskell or CL. I expected the Haskell examples to look alien and the CL to look familiar, but the idiomatic Clojure solutions to the examples are almost identical to the Haskell solutions. E.g. take 5 . filter (not . p) . drop 3 becomes (->> s (drop 3) (filter (complement p)) (take 5)) ; for some sequence s I think it is also true of Clojure that it strives to have many small functions with a high degree of composability.
- behnamoh 6y agoIs there something similar to (->>) in Haskell? Edit: corrected “—>”.
- Ixiaus 6y ago`.` is function composition in Haskell (used in the example).
- eru 6y agoInterestingly function composition is also the mapping operator (fmap) for the corresponding functor.
- rbonvall 6y agoYou can create it yourself: Prelude> s ->> f = f s Prelude> [1..100] ->> take 10 ->> filter (not . odd) ->> drop 3 [8,10]
- jim-jim-jim 6y agoI think `&` is this function. In Data.Function.
- eru 6y agoOr you can use >>> from Data.Function, if you prefer to go point-free.
- seisvelas 6y agoReminds of the difference between Unix and GNU. I wonder to what extent RMS's Lisp background influenced GNU's kitchen sink tendencies.
- owl57 6y agoThe remove-if-not example is pretty funny. No, it doesn't have any obvious translation into function composition, and in particular isn't equivalent to the Haskell example. Instead, :count specifies how many elements to remove and :start specifies when to start removing.
- wrs 6y agoCommon Lisp doesn’t just have LOOP, it also has Series [1]. I think the actual philosophical difference may be that Haskell does this with compiler support for stream function composition, whereas Common Lisp does it with a set of language-level macros any user could write (if they were as smart as Richard Waters). [1] https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node347.html https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node347.html
- _delirium 6y agoTo get a feel for how these compare, the Common Lisp Cookbook gives some examples for how to do different common operations using the loop, series, and iterate packages: https://lispcookbook.github.io/cl-cookbook/iteration.html https://lispcookbook.github.io/cl-cookbook/iteration.html
- dllthomas 6y agoStream fusion in Haskell is done with rewrite rules. On the one hand, it's totally true that you're no longer really writing Haskell, and the facility for rewrite rules itself needed (at some point) to be added to the compiler. But at this point I can make my own data structures fuse (potentially in new ways) without further changes to the compiler. https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#rewrite-rules https://downloads.haskell.org/~ghc/latest/docs/html/users_gu...
- dan-robertson 6y agoStrictly speaking, Common Lisp does not have series because they were not included in ANSI Common Lisp. Therefore even though you could use the macros provided with a separate streams package, you’d need to make sure that all your code used that package (rather than the CL definitions of let and lambda and so on) and properly declared stream functions. This ends up making code using streams not super composable which isn’t great. I also think it’s a bit unfair to say that Haskell’s stream fusion requires special compiler support. The compiler doesn’t recognise list functions specifically or have special cases for list-looking-types (except for syntax). Instead there is a general mechanism to say “at stage number x, replace expressions that look like y with z”, where there are something like 10 stages and expressions y and z are type checked so these transformations are only applied in “valid” cases. I think saying that this is special compiler support for stream fusion is like saying that macros are special compiler support for series in CL. A final thing to note is that because of lazy evaluation, stream fusion in Haskell doesn’t change the semantics of the Haskell list functions from how they would behave without it. In Common Lisp streams must be explicitly separated from lists because they are semantically different (in the evaluation order of the functions that act on them).
- avindroth 6y agoThere is a strange... kind of poetry with Haskell. It is like math on wheels, math applied to procedures, math with... time. Its appeal to me is like the appeal of math to me, not like real analysis math but abstract algebra math. The beauty, the purity of mathematics of younger days that once became lost after encountering the sad complexities of the world. Understanding every little aspect and being able to prove every part is now a luxury, and interfacing without real understanding is the more practical approach in the turbulent waters of poorly connected technological and social systems. But still there is hope and there are dreams. We like to drench ourselves in dream qualia sometimes, and Haskell and pure math are that medium. The abstractions of it, the consistency of it, the purity of it... When Haskell is called a pure language, it almost goes beyond the static definition of functions being pure, and describes the general feeling that occurs when writing Haskell. You feel pure. You feel like you are taking these small parts and creating greater parts in an elegant buildup of abstractions, traversing one level higher and one level lower at your whim. Lisp... maybe it’s the parentheses, maybe it’s something else... it never really caught onto me like Haskell did. Haskell feels pure and dream-like and perhaps unsuited to the world where (if you really get down to it) abstractions and types are just useful ‘human’ inventions and unfit for every usage. The world is for getting down and dirty, and mathematics, or at least the pure side of it, really isn’t. The representative mathematics of Haskell is Category Theory, and it is just as far from the level of “real” as it can be. More abstract than abstract algebra, if you will. Abstraction itself is an intellectual operation that is also rooted in emotional detachment. Perhaps Haskell represents that kind of ideal in a modern world where practicality pays before purity.
- sillysaurusx 6y agoI dislike the lisp convention of remove-if, remove-if-not, etc. Filter and take isn't much better. The python convention is much nicer: [x for x in foo if x not in y] Turns out, this can be expressed in Lisp: (list x for x in foo if x not in y) I've implemented this into my fork of Lumen that runs on Python. https://github.com/shawwn/pymen https://github.com/shawwn/pymen It feels very nice to use: > (list x for x in (range 10) if (= (% x 2) 0)) """ Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. """ [0, 2, 4, 6, 8] > It wasn't even that ugly to implement. It's ~20 lines: https://github.com/shawwn/pymen/blob/1c191c9e00e73303a6479f8f56ecb0ba84bb1566/macros.l#L27-L55 https://github.com/shawwn/pymen/blob/1c191c9e00e73303a6479f8... One other neat thing is that the REPL prints out the docstring of the last evaluated thing by default. It makes it nice to explore libraries: > (import numpy as np) https://imgur.com/1rpF95y https://imgur.com/1rpF95y > np.vsplit https://imgur.com/OjIvTWt https://imgur.com/OjIvTWt It's like an automatic help() call on the last evaluated thing. (If anyone happens to try it out, you can get into a REPL by running `rlwrap bin/pymen`, or just `bin/pymen`.)
- garethjrowlands 6y agoFor those that didn't know, Haskell does of course have list comprehensions: [x| x <- foo, not (elem x y)] Here's an example finding consonants: [c| x <- ['a'..'z'], not (elem x) $ "aeiou"]
- dwohnitmok 6y agoHaskell's list comprehensions actually started off as more general monad comprehensions, were later restricted to lists, and are back behind a GHC language pragma.
- centimeter 6y agoNo need for the dollar sign in the second example :) A nice thing about Haskell list comprehensions is they're based on a trivial transformation to monad syntax, which makes it easier to factor out complex list transformations into multiple little bites. I've run into this problem in Python. Also, Python list comprehensions can often behave very unexpectedly due to mutability. Here's an example of the monad syntax: [(x,y) | x <- [1..10], y <- [1..x], odd (x + y)] equiv do x <- [1..10] y <- [1..x] guard $ odd (x + y) return (x,y) Lots of combinatorics problems can be elegantly solved using the list monad like that.
- sxp 6y agoJavascript and Python have similar capabilities, but they're missing the stream fusion optimization mentioned at https://chrisdone.com/posts/stream-composability/ https://chrisdone.com/posts/stream-composability/ Javascript: a = [...Array(20).keys()] p = x=>!(x%2); a.slice(3).filter(p).slice(0,3) Python: a = range(20) p = lambda x: not x%2 filter(p, a[3:])[:3]
- pjc50 6y agoYou can also do this nicely in Linq in C#.
- sergeykish 6y agoThe code is not equivalent to Common Lisp (neither is Haskell version), it should remove `count` of elements from the `start` matching a predicate (remove-if-not #'evenp '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) :count 5 :start 3) (1 2 3 4 6 8 10 12 14 15) a = (1..15) r = [] c = [] a.each.with_index do |e, i| if i <= 3 r << e elsif c.length < 5 if e.even? r << e else c << e end else r << e end end r #=> [1, 2, 3, 4, 6, 8, 10, 12, 14, 15] I can see no simple way to compose this a = (1..15) l = a.take(3) c = 0 m = a.drop(3).map.with_index { |e, i| [e, i, e.even?] }.take_while { |e, i, p| c +=1 unless p; c <= 5 } _, last_m_index, _ = m.last m = m.filter { |e, i, p| p }.map { |e, i, p| e } r = a.drop(3 + last_m_index + 1) l + m + r #=> [1, 2, 3, 4, 6, 8, 10, 12, 14, 15]
- anentropic 6y agoin Python 3 both range and filter are lazy but the slices here would spoil it there is https://docs.python.org/3/library/itertools.html#itertools.islice https://docs.python.org/3/library/itertools.html#itertools.i... islice however...
- pizza234 6y agoUnrelated to the main subject, but I wonder why in the shell example the user is asked to write all the numbers from 1 to 10 (via cat!), when `seq 1 10` is equally expressive, and much more coincise.
- jim-jim-jim 6y agoI've noticed that these differing approaches lead to argument order being flipped sometimes. https://wiki.call-cc.org/man/5/Module%20(chicken%20string)#string-split https://wiki.call-cc.org/man/5/Module%20(chicken%20string)#s... Because Chicken's `string-split` expects its delimiter to be optional, it wants a string first. https://hackage.haskell.org/package/text-1.2.4.0/docs/Data-Text.html#v:splitOn https://hackage.haskell.org/package/text-1.2.4.0/docs/Data-T... While Haskell's emphasis on composition means it's more logical for the constant parameter—the delimiter—to be provided first. It's not a great example, but the first one I can think of. The difference is starker when the Lisp command has many more parameters than the Haskell one, with some of them being optional. When trying to write cute point-free code in Scheme, I found myself using `flip` too much for it to be fruitful.
- thomasahle 6y agoI hate when I have to do flip. Dislike reading it even more. I don't know what the solution is, other than using points..
- mark_l_watson 6y agoI really enjoy programming (a lot!) in both Common Lisp and Haskell, and I agree with his comments on both languages. Chris and I probably differ in that I love the kitchen sink built in functions. Also, it is also common to write lots of very short Common Lisp functions.
- GuB-42 6y agoA small note: composition is not better than monolithism. The article makes it feel like it is but it is not. They are two perfectly valid approaches when it comes to solving problems. Often a mix of both is used. Monoliths tend to be better at solving common real life problems efficiently while composition is better suited for unexpected abstract problems. We need both. For example GNU binutils are not very "unixy", with plenty of "monolithic" options but they still work well with pipelines.
- greg7mdp 6y agoI disagree. With composition we have general building blocks which can be combined in an infinity of ways, and remain available to combine with newly added functions. The monolith way provides a fixed, non upgradable set of possibilities, so if your need does not fall into what already exists you need to add yet another monolith (see remove-if vs remove-if-not).
- tester89 6y agoI mean the -if vs -if-not is really more for typing convenience, the current CL standard actually recommends against -if-not functions because you can do composition `(remove-if (complement #’predicate) sequence)`
- schemy 6y agoChange the Haskell example to read 3 and 5 as n and m from an external file. All of a sudden your beautiful code is now a huge mess and you need to refactor the one liner into at least three separate functions to try and keep the Maybe types from taking everything over. Meanwhile in lisp I would have written a special drop3-take5 function in the first place. Then refactoring it would just take replacing 3 with n and 5 with m, adding n and m as arguments and writing a function to read whatever the config file is.
- vore 6y agoIsn't that the exact same thing you would do in Haskell? How you read from a config file in Haskell seems irrelevant here, and troubles with it are more related to purity than composition. dropNTakeM p n m = take m . filter p . drop n
- lispm 6y agoThe LOOP macro is actually a very different approach: it's an embedded domain specific language for iteration tasks. The language is thought to be more natural (-> 'conversational') than formal -> an actual influence from Interlisp, where this macro originally came from. If we talk about the approach of using larger building blocks with named parameters, that's also typical in UNIX, since most UNIX commands have zillions of named arguments, even more so than typical Common Lisp functions. Typically it is easier in using interactive command languages to fill out common options to a command, than to write programs. For example 'ls' does not expose a bunch of functions to combine, but is a powerful command with lots of named options: https://man7.org/linux/man-pages/man1/ls.1.html https://man7.org/linux/man-pages/man1/ls.1.html Named parameters/arguments are not generally common in Lisp. Emacs Lisp did not have them and wanted to avoid them explicitly.
- ajarmst 6y agoThis seems to imply that extensive use of composition in Haskell is a notable stylistic decision rather than an entailed effect of the fundamental design choices (first-class functions, lazy evaluation, type classes) that explicitly encourage such composition and a terse, mathematical syntax that makes the composition operation obvious. Heavy use of Composition is idiomatic in lisps, too. It’s just the syntax doesn’t rub your face in it: It’s pretty common to see form in lisp that ends in a dozen close-parentheses as we see chains of forms being passed as arguments to other forms. It would be weird if composition wasn’t idiomatic in a language with first-class functions. The loop macro isn’t good evidence: it’s notable precisely because of its difference from typical lisp usage. I’ve heard lisp programmers claim to refuse to use loop because it clashes with the rest of the language. I’m less interested in purity, and it is so convenient sometimes...if only as a clear illustration of just how much power and potential for abuse the CL macro system provides. Amd let’s just leave CLOS and metaobject protocols under the tarp for now :-)
- eru 6y ago> It’s pretty common to see form in lisp that ends in a dozen close-parentheses as we see chains of forms being passed as arguments to other forms. That's just a chain of function applications. Function composition puts the emphasis on the fact that functions are values in their own right and can be manipulated (eg with a composition operator) as objects without regard to any values they might act on. If you want to see one Haskell equivalent of loop, https://hackage.haskell.org/package/monad-loops-0.4.3/docs/Control-Monad-Loops.html https://hackage.haskell.org/package/monad-loops-0.4.3/docs/C... has got you covered.
- ajarmst 6y agoI’m not convinced that chain application and composition are meaningly distinct in anything but a syntactic sense if the language in question offers first-class functions and deterministic evaluation (eg no side effects). In mathematics, composition ($f \circ g$) is invariably described in terms of chaining f(g())—in fact, the composition operator is usually defined as alias for chaining. Yes, there are subtleties I’m glossing, but I don’t think support the thesis that function chaining and composition are significantly different at this level (i.e. the level of syntax and idiom rather than the level of Category Theory).
- dleslie 6y agoThere's a more fundamental philisophical difference: Common Lisp promotes the use of doclines and apropos tools in order to discover and understand behaviour, with symbol names that tend to describe the function of what they represent. Haskell leans on type signatures and symbolic operators. IMHO, a pseudo-random sequence of non-word symbols tied to a type signature is of very little use. IE, something fabricated: (-*/) :: A -> M c -> B Ah yes, so understandable.
- vore 6y agoPeople who write Haskell don't just leave their symbolic operators undocumented. It's definitely heavy on the symbols but that and type signatures are certainly not the only tools Haskell devs have.
- dllthomas 6y agoOn the one hand, the parent's comment is certainly hyperbole. On the other hand, it's also the case that too any Haskell projects are under-documented. Probably worse than the typical language, and certainly worse than the best-in-class. On the gripping hand... while types make poor documentation, they are always correct documentation, and they are automatically generated documentation. When I write Python or (apparently) Common Lisp, I can expect to get reasonable documentation by interrogating anything someone hands me. In Haskell, insofar as I have learned to get good information from the types, I get some (correct!) documentation for things that I have newly assembled myself!
- newen 6y agoI find type information for functions incredibly useful. I get so lost in Python code once it get past a certain size even after years of Python programming experience because of the its lack of ability to put a useful amount of structure into the code. After having programmed in Haskell for a while, I just miss tabbing a function and being able to see its type signature.
- 6y ago
- schemy 6y agoThe main difference is that in lispy languages you wouldn't use the language itself to solve the problem. You'd extend it. I'd write a function that is (drop3-take5 test list) which does exactly what it says. This might seem like huge overkill, but when the specs change and I need to set the start and stop from a config file I can easily refactor drop3-take5 into (drop-n-take-m n m test list), with a let around it to read the config. drop3-take5 would look something like: (define drop3-take5-list (lambda (ls filter) (define internal (lambda (ls matches) (cond ((null? ls) '()) (else (if (filter (car ls)) (cond ((< matches 3) (internal (cdr ls) (1+ matches))) ((<= matches 5) (cons (car ls) (internal (cdr ls) (1+ matches)))) (else '())) (internal (cdr ls) matches)))))) (internal ls 0)))
- vore 6y agoThis seems like an unsustainable approach: will you need to write these bespoke functions for any combination of behaviors you would need?
- schemy 6y agoLisp is about writing a dsl that solves your problem. It just happens to be an s-expression dsl. Exactly how it works depends on the problem domain. But in my experience a lisp dsl is much less brittle than trying to map the problem into a haskell program, especially with a changing spec. This is a bad example because it is so contrived to show off the strengths of haskell. As an example for the strengths of lisp: I wrote a logical dsl that adds a boolean dependent type system to scheme using macros. It's 400 lines long and copies all the bits from Idris I needed and it still feels like a scheme and is fully interoperable with regular scheme.
- bananaface 6y agoOk, now it fails - how are you going to interpret the stack trace?
- 6y ago
- wudangmonk 6y agoThis is really just talking about which functions they decided to include in their standard library. Clojure for example takes the haskell approach so its not a question of composability vs monolith. Sure composability is nice and should probably be the way you start creating something but after you are satisfied that it works the way you want it to and you want to make it more efficient you will go monolith and treat this new thing as a bigger piece you can compose with. Someone new can the come along, fail to understand why its a monolith and decide to make it better my making it made up of composable parts again.
- tester89 6y ago> One difference in philosophy of Lisp (e.g. Common Lisp, Emacs Lisp) and Haskell is that the latter makes liberal use of many tiny functions that do one single task. This is known as composability, or the UNIX philosophy. This honestly seems like a misunderstanding which ignores how many POSIX commands actually accept commands. The uni philosophy doesn’t mean literally one thing, but rather one task; sometimes the task will have different parameters and that’s OK, but we’re not going to have `ls` takeout the trash.
- george120 6y agoFor marketers who’ve been keeping an eye on the SEO landscape for a few years now, you’ll know that Google has made several big changes to their search engine algorithms. So far, there’s been Panda, Penguin, Hummingbird, and Pigeon, as well numerous 2.0, 3.0, and 4.0 updates to those as well. If you lost track of that zoo, you’re not alone, and many marketers have gone the past few years thinking that if you stuff enough keywords into your website, you’ll be fine. That won’t exactly get you where it used to 5 years ago, however, because today’s algorithms have more emphasis on optimizing the pages for the user – not just for search engine crawlers. Another one of the big problems you see with SEO today is how marketers approach it. While many marketers consider all things SEO to fall under one umbrella of activities, there are actually two distinct branches to be addressed: on-page and off-page SEO. To help you learn more about the in’s and out’s of each, and re-tune your current strategy to be up-to-date, here’s a thorough overview and explanation of some best practices: What is On-Page SEO? When you think of the most basic search engine optimization tactics like using keywords in your copy and optimizing the meta description, HTML code, title tags, and alt tags, that’s the foundation for on-page SEO. On-page SEO refers all the measures that can be taken directly within your website to improve its position in the search rankings. This includes those basic tactics listed above, but also takes into consideration things like overall content quality, page performance, and content structure.https://www.bloggerzune.com/2020/06/Off-page-seo.html?m=1 https://www.bloggerzune.com/2020/06/Off-page-seo.html?m=1
- devin 6y agoI was a bit puzzled. Clojure seems to provide both avenues. The "Common Lisp" version: (for [i (range 1 10) :when (even? i) :while (< i 5)] i) A Haskell-y version (according to the article): (->> (range 1 10) (take-while #(< % 5)) (filter even?)) Using Clojure's transducers: (into [] (comp (take-while #(< % 5)) (filter even?)) (range 1 10))
- dllthomas 6y agoUh guys? [1]> (remove-if-not #'evenp `(1 2 3 4 5 6 7 8 9 10) :count 3 :start 1) (1 2 4 6 8 9 10) As pointed out by owl57, the Haskell translation is incorrect and the correct implementation isn't quite so trivial. I don't see a way to pull the :count argument out into a separate function. We certainly can for skip, though, and I might. Prelude> skipThen 1 (removeIfNot even 3) [2,3,4,5,6,7,8,9] [2,4,6,8,9] as implemented: removeIfNot p count = go count where go _ [] = [] go 0 list = list go n (x:xs) | p x = x:go n xs | otherwise = go (n - 1) xs skipThen count f list = let (pre,suf) = split count list in pre ++ f suf
- dan-robertson 6y agoYou’re lisp syntax is weird but you’re right: The start argument specified where to start removing things and the end or count arguments specify where to stop removing things (ie at an index or after a certain number of elements respectively). I claim this is a pretty good argument against the keyword arguments as they don’t necessarily do what one expects.
- tsimionescu 6y agoHonestly, I think the mistake comes from thinking of `remove-if(-not)' as `filter'. When I see code saying (remove-if #'condition '(1 2 3 4 5 6) :start 5 :count 3), I would be pretty surprised if it removed anything prior to the 5th element. :count is worse, just by looking at this code I would not be sure whether it would always remove 3 elements (at most) or if it would remove all elements within a subsequence of 3 elements starting at index 5.
- sergeykish 6y agoThank you, I've mailed author, he updated the post > UPDATE 2020-08-03: I no longer stand by the content in this post. I think the overall sentiment is marginally accurate; however, the details in the post are incorrect (as many have pointed out over the years). > As has been pointed out, remove-if-not’s start/count parameters behave differently and cannot easily be separated out of the function, a design trade-off that I appreciate.
- nabla9 6y agoDeeper philosophical differences: * Lisp is multi-paradigm languages. Haskell is pure functional language. * Haskell wants to be mathematics. Lisp wants to be an operating system. I believe the composition vs. monolithism difference comes from these deeper differences.
- lispm 6y ago> Lisp wants to be an operating system. Lisp wants to be interactively used.
- dan-robertson 6y agoI think it should be stressed that most languages (except maybe bash I guess) can’t provide the kind of compositionality that Haskell does. This is because Haskell’s lazy evaluation allows these compositions to do an asymptotically appropriate amount of work. Consider this Haskell: xs = [1..20] p n = if n < 13 then even n else p n ys = take 5 . filter p . drop 3 $ xs main = print ys If a strict language were being used then the processing would be as follows: 1. drop 3 ys is [4..20] 2. When computing filter p [4..20], everything is ok up to 12, but computing p 13 goes to an infinite loop. 3. We never get a result to compute take 5 of. Because Haskell is lazy, it will not try to compute p 13 and so can do the right amount of work. Perhaps a more reasonable example would be that if the list xs were really long, a strict program would have to evaluate p against every element before taking the first 5 results (so it would take linear time if p were constant time) while a lazy program would only need to compute p on enough elements to collect 5 results. Common Lisp was designed for older, slower computers than Haskell and to be able to make programs which were reasonably efficient. It also had strict evaluation and so with this context, the extra arguments to many functions for special cases (which lots of people didn’t like) or the combined iteration of loop (which lots of people didn’t like) make a lot more sense.
- sukilot 6y agoSince bash and the Unix core utils are written in C, I strongly challenge your claim that "most languages" can't do stream processing. You don't have to have a lazy language to implement a lazy data type.
- bollu 6y agoThe difference is between pervasive laziness (laziness by default) v/s laziness by opt-in. If you have laziness by opt-in, then most parts of the language will not opt-in [from prior experience with, say, racket which also has lazy streams]. It's the pervasive and efficient compilation of laziness in Haskell which makes it actually useful to write lazy programs. Now, am I a fan of writing lazy programs? No, I find the upshot of referential transparency gained by laziness to be overshadowed by the warts it brings --- lack of a good debugging experience, tie-the-knot semantics being fragile, etc. I'd rather live in a strict total programming language. But one cannot "handwave" away laziness in haskell that easily by saying "you can emulate it in $STRICT_LANGUAGE". By the exact symmetric argument, one can emulate strict code inside haskell: just use `ST` or `IO`. But very rarely does one see whole libraries written strictly, because this style of code doesn't compose with the (default) laziness and purity in haskell.
- mtraven 6y ago> One difference in philosophy of Lisp and Haskell is that the latter makes liberal use of many tiny functions that do one single task. This is known as composability, or the UNIX philosophy. Have you ever looked at a Unix man page? And while Common Lisp has some functions that might be swiss army knives of functionality, that is not "the philosophy of Lisp", it's a particular style. Clojure and Scheme are just as much Lisp as CL, and as other people have noted, their style is very similar to Haskell.
- etangent 6y agoWhen I started out with Python, I was learning Haskell in parallel. As a result, my early Python code ended up being influenced by Haskell (I wrote many small functions that performed a single task). But it was somewhat frustrating. Later, I developed my Python style and began heavily relying on optional arguments through `kwargs` and duck typing. That made my programs much more effective and easier to reason about. Now I realize that my later Python code became more Lisp-like.
- ACow_Adonis 6y agoI'm a little bit confused about the notion that composition isn't used much in lisp as opposed to Haskell. Isn't composition literally the benefit of S-expressions, prefix notation, and everything being a function?
- smabie 6y agoLisps lack implicit currying, so function composition becomes much more verbose. And functions aren't that important in CL, not everything is a function and CL is usually written in an OOP or procedural style. CL is more about data and AST composition then anything else. Moreover, CL is a lisp-2, so in a very real sense, functions are second class citizens in the language.
- pfdietz 6y agoOr, you use reader macros to make currying concise. https://github.com/eschulte/curry-compose-reader-macros https://github.com/eschulte/curry-compose-reader-macros Functions are not second class citizens. They are privileged with their own namespace. That's a perk, not a penalty. One notable form of composition in CL is method combination. Does any other language support something like that?
- smabie 6y agoHaving to prefix functions with #' is a perk? No other language uses a separate name space for functions, and for good reason, because it sucks.
- pfdietz 6y agoIt's an optimization for usability. Many more symbols occur as the heads of list forms than appear after #'. So, the common case is optimized for clarity and the relatively uncommon case requires two extra characters. I completely disagree that it sucks. What sucks is having to remember not to have your variable names collide with your function names (or indeed any of the other namespaces in CL). Things that are usually used in different ways benefit from having separate namespaces.
- _prototype_ 6y agoI write simple lisp functions that are not "configured" as this guy is saying. Not sure I agree. The philosophical difference he talks about seems more of a paradigm choice than a inherent language construct
- euske 6y agoI tend to think that most natural languages use the same kitchen sink approach like Lisp, and as a consequence it has a sprawling set of vocabulary. For some peculiar reason, people seem to like it that way. So, naturally speaking, I guess Lisp is probably going to be more popular than Haskell.
- quickthrower2 6y agoI am less experienced than OP, but I got the impression the philosophical difference is that with Lisp, you are trying to abstract things with a simple language and AST code generation (macros) whereas in GHC Haskell you are trying to abstract things with a very in depth language, heavily based on mathematical ideas (see all those language extensions!).
- eru 6y agoYes. Though in theory you could use Haskell with a Lisp-like syntax just fine. Many of the language extensions are sugar over a simpler (implied) core of the language. Some are purely syntactic, like NumericUnderscores. Some others like GADTs are semantic, but still mostly explained in terms of mapping to this simpler language.
- karmakaze 6y ago> One difference in philosophy of Lisp (e.g. Common Lisp, Emacs Lisp) and Haskell is that the latter makes liberal use of many tiny functions that do one single task. This is known as composability, or the UNIX philosophy. I would rather say that each tiny function handles one factor and that a program is the decomposition into factors. Lisp also composes functions but are chunkier and can be ad-hoc one-offs. Static types vs runtime errors is another point of difference.
- eru 6y ago> Having written my fair share of non-trivial Emacs Lisp (and a small share of Common Lisp; I’ve maintained Common Lisp systems) and my fair share of non-trivial Haskell I think I’m in a position to judge. While I prefer Haskell, judging Lisps by Emacs Lisp isn't entirely fair. It's probably the worst Lisp in somewhat wide use. ('newLisp' is worse, of course. But thankfully no one in their right mind uses it.)
- sukilot 6y agoIt's a shame that that blog post's buggy Haskell the breaks the rhetorical argument has been live for 5 years and never corrected or withdrawn.
- wirrbel 6y agoIts a great article, unfortunately it barely mentions Lisp's function composition capabilities and thats a bit unfortunate because it makes I guess a nice case for differences in API design in Haskells standard library and Common Lisp's. Lisp did in fact pioneer the introduction of higher-order functions and function composition into programming language and its fairly remarkable that lisps are still around and highly versatile / usable. What's being shown are Collection Pipelines(https://www.martinfowler.com/articles/collection-pipeline/ https://www.martinfowler.com/articles/collection-pipeline/) which can be implemented in lisp and in fact are. Clojure and Scheme for sure have these procedures and I am sure they are available for common lisp as well. Whether one prefers Haskell or Lisp is probably in parts a subjective decision (and also has to do with socialisation). I think I am falling onto the lisp side of things because of the explorative nature of programming and I had my heureka moment of programming with Test-Driven Development and for some reason I am gravitating to that in my programming and its easier to do TDD without a type-checker actually. For anyone who is curious about exploring Lisps, I suggest having a look at Clojure or Common Lisp (potentially Dylan if you don't want to bother with parentheses) and not Scheme (because it doesn't have polymorphism and is heavily fragmented).
- galaxyLogic 6y agoI think it is much because Common Lisp standard library was written in the keywords-fashion. I assume it could have been written also using small composable functions. No?
- sergeykish 6y agoGuys, it produces different results, check yourself Prelude> take 5 . filter even . drop 3 $ [1, 2, 3, 4, 5, 6, 7, 8, 9] [4,6,8] (remove-if-not #'evenp '(1 2 3 4 5 6 7 8 9) :count 5 :start 3) (1 2 3 4 6 8)
- kazinator 6y agoThe main difference is that Haskell is a very specific language, whereas Lisp is a family. Not all the members of the family are based on exactly the same philosophy. The remove-if-not function just a Common Lisp thing. And, by the way, at the bottom of its description in the standard, we find this: The functions delete-if-not and remove-if-not are deprecated.
- pfdietz 6y agoThat deprecation is meaningless, since there is no standard body to revise the standard, and users are perfectly willing to continue to use those functions.