Hacker News new | past | comments | ask | show | jobs | submit login

Nil is monoid-zero – what do you think of this idea?

    assoc {}               (assoc nil :a 10) => {:a 10}
    concat '()             (concat nil '(a b c)) => (a b c)
    str ""                 (str "abc" nil) => "abc"
Except where host language interop is prioritized:

    comp identity          ((comp nil inc) 42) => NPE
    + 0                    (+ 1 nil) => NPE
    * 1                    (* 1 nil) => NPE
AFAICT, everywhere where nil could be sensibly defined as zero without complicating interop, it is. And we can of course pave over the interop examples with `fnil`.



Paving over the difference could seem convenient but it smells like a possible source of non obvious coding errors. AFAIK it's still worthwhile to know the difference between function identity and the value that produces identities.

Though, lots of this is inherited from common lisp where the list operations have more to do with lambda calc and the physical construction of the old lisp machines than they do anything else.


Hi dustin.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: