TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Affordance and Concision

14 pointsby fogusover 12 years ago

3 comments

noelwelshover 12 years ago
Good post.<p>I tend to think of Lisp/Scheme logical and conditional operators taking an implicitly defined monad for the type of "useful value" or "nil" (#f in Scheme). It's just that:<p>1. You can't add new instances to the type class. 2. The language doesn't check you handle the failure case.<p>If there was a monad type class you could create a type "useful value" or "exception" (called Validation or Either in Haskell and Scala) and have the same concise code. However, without a static type system this kind of system just gets unmanageable (I know, I've tried it).<p>Proponents of dynamic typing often wax lyrical about the benefits of escaping the straight-jacket of static typing. They often don't appreciate the kinds of programs that are impossible to write without a modern type system. NB: this post is not one of them.
islonover 12 years ago
What about a get-or-throw that throws an exception if it can't find the key? You get the best of both worlds.<p><pre><code> (defn get-or-throw [m k] (or (get m k) (throw (RuntimeException. (str "could't find key " k " in map " m))))) </code></pre> I understand most people use the simpler (key map) or (map key) forms instead of get, but at least you have an option.
评论 #5165434 未加载
sp332over 12 years ago
I like this poem linked to in a footnote: <a href="http://www.apl.jhu.edu/~hall/lisp/Scheme-Ballad.text" rel="nofollow">http://www.apl.jhu.edu/~hall/lisp/Scheme-Ballad.text</a>