Luke Palmer

lukepalmer.wordpress.com · Personal blog · on HN since 2009

Luke Palmer writes about Haskell, functional programming, and software design ideas such as the Omega monad and the existential typeclass antipattern.

What HN saysHN commenters cite his existential typeclass antipattern post when discussing overuse of type classes, and link his posts on tricks like the reverse state monad.
35HN people shared it
14linked it in comments
35stories submitted
430story points
6 years agolast shared
2009people per year2026

Most-shared posts

  1. 1
    Haskell antipattern existential typeclass
    5 people · first shared 2010
  2. 2
    Mindfuck the reverse state monad
    3 people · first shared 2012
  3. 3
    Disrespect in Education (2014)
    2 people · 81 points · first shared 2014 · 73 comments on HN
  4. 4
    Programming for a culture approaching singularity
    2 people · 31 points · first shared 2010 · 20 comments on HN
  5. 5
  6. 6
    Encapsulation Considered Harmful
    2 people · 8 points · first shared 2010 · discussion on HN
  7. 7
    Information Economics - It is still early in the game.
    2 people · 3 points · first shared 2011 · discussion on HN
  8. 8
    Semantic Design
    2 people · 3 points · first shared 2013 · discussion on HN
  9. 9
    Emphasizing Specialization
    2 people · 1 points · first shared 2009 · discussion on HN
  10. 10
    IDE WTF
    1 people · 173 points · first shared 2010 · 139 comments on HN
  11. 11
    What I don’t like about Python
    1 people · 48 points · first shared 2009 · 17 comments on HN
  12. 12
    Lazy Partial Evaluation
    1 people · 24 points · first shared 2009 · 2 comments on HN
  13. 13
    My Premonition
    1 people · 8 points · first shared 2009 · 2 comments on HN
  14. 14
    Forever Unemployed
    1 people · 6 points · first shared 2009 · discussion on HN
  15. 15
    My paradigm is better than your paradigm
    1 people · 6 points · first shared 2011 · discussion on HN

What HN people wrote when they linked it

endgame · 2018-04-20
> If you take FP to its logical conclusion, FP is a slippery slope that eventually leads to Monad-Transformer centric designs. I don't understand what you mean by this, and I write production haskell for a living. We don't have teetering towers of transformers, and the best advice I've seen is often "put away the shiny tools and just use functions", https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existe… . Similarly in http://www.parsonsmatt.org/2018/03/22/three_layer_haskell_cake.html , which is like one real transformer layer and a way of claiming only the capabilities you need in your impure code. His "invert your mocks" article talks about this, too. Ed Kmett's comments on Scala make me worry that the "solid foundation" isn't as solid as it could be: https://www.reddit.com/r/haskell/comments/1pjjy5/odersky_the_trouble_w… . How much of this is true in more recent Scala versions?
crntaylor · 2012-10-16
Why the focus on type classes? Yes, type classes can sometimes be very helpful (the Num, Monad and Functor typeclasses in Haskell for example - where would we be without them?) But overuse of type classes in any language is an antipattern. Luke Palmer sums it up well in his blog post [1] Advanced type system features have their place, but plain old functions go a long, long way. Functions are the masters of reuse: when you use an advanced feature, you need a yet more advanced feature to abstract over it. But all you need to abstract over a function is another function. Using type classes where they're not appropriate leads to 1. writing unnecessary boilerplate code, 2. torturing the type system and 3. a slippery slope of adding more and more advanced type system features to bludgeon your poor design choice into the right shape. Use functions! It's also worth reading Gabriel Gonzalez's post on a similar topic [2] [1] http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existen… [2] http://www.haskellforall.com/2012/05/scrap-your-type-classes.html
tikhonj · 2012-08-07
Obviously it doesn't actually violate the laws of causality. However, it looks like it does. At a high level, I think this is essentially similar to the "time travel" you can get with continuations[1]. The first blog post[2] linked in the readme should make things clearer. [1]: http://matt.might.net/articles/programming-with-continuations--excepti… [2]: http://lukepalmer.wordpress.com/2008/08/10/mindfuck-the-reverse-state-… Essentially, a "stateful value"--that is, a value that could be based on some state coupled with that state--is just a function from the state to the value and the new state. It has the type s → (α, s) where s is the type of the state and α is the type of the value. This is the simplest way to represent state in a purely functional way. To actually use it, you have to supply the initial state and you then get the value and the new state. When you actually use it, you plug the state in to get the value and the next state. Then you go to the next function you want to run, plug the new state into that and so on. The whole program looks neat thanks to do-notation: stateful = do currentValue ← get put (currentValue + 1) return ("x_" ++ currentValue) If the current state is 0, stateful gets 0, increments the state and returns "x_0" wrapped in the new state (1). If you sequence two statefuls one after another, you get "x_0" followed by "x_1". The trick is…
jerf · 2010-02-20
I don't know about that. When you get to the "second-level" stuff, it can be weird. Lately, partially as an exercise and partially to get a project of mine going the way I'd like to see it going, I've been working with the State monad directly. Using the state monad is trivial. Understanding how the state monad does its thing is slightly less trivial, but just a matter of following along the definitions and doing the appropriate substitutions. Understanding where the state monad came from and how to modify it to do what I want... now that's starting to get tricky. I blundered around for a bit trying to reconstruct the state monad without actually looking at it and came to the conclusion it wasn't possible. Except that it clearly is possible because it's part of the standard library. The problem was that it had never really occurred to me to put a function in the type signature itself, the way the state monad does, and despite how simple it looks it has really hit home that I don't really grok the thing yet. I do not mean to overmystify; like I said I follow the thing perfectly well, a minimal and perfectly functional definition of the thing is like 10 rather simple lines and there's an upper limit to how confusing 10 lines can get, but... if you can't modify something you certainly don't grok it. Yesterday night I realized I have felt this way before, but it had been such a long time that I hadn't instantly recalled it. I felt this way when I learned about pointers. My…
dllthomas · 2020-06-16
This sounds like the Existential Antipattern, from Haskell land. I don't know to what degree it translates to this setting. https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existe…
danieldk · 2016-01-20
Ad-hoc polymorphism is valuable, and objects represent a clear way to express it You can do ad-hoc polymorphism using type boxes (existentially quantified type classes). Of if you think this is an anti-pattern, just plain old data structures plus (first-class) functions: https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existe… Thin wrappers that slightly change functionality are often a business requirement, and "extends" inheritance provides an easy way to express them So does composition. In OO style it's immediately clear what I can do with my user info, because it's all methods on the object The problem with this is discussed in the linked article. Edit: I see that you do Scala, so all of this is not news to you ;).
tel · 2014-08-10
A good example demonstrating this is the "reverse state monad" http://lukepalmer.wordpress.com/2008/08/10/mindfuck-the-reverse-state-… It sends state updates "back in time" to compute fixed points. The above article shows how you can compute the fibonacci stream using it.
ky3 · 2012-11-12
Dan Doel [1], who works with Edward Kmett, gets it too. And there's the inimitable Luke Palmer [2], whose blog contains nuggets of gold for those who care to dig through the archives. [1] http://www.reddit.com/user/doliorules [2] http://lukepalmer.wordpress.com/tag/haskell/
mbrubeck · 2012-01-24
http://lukepalmer.wordpress.com/2012/01/19/sentences-and-paradigms/ is an interesting look at parallels between declarative programming (as in Prolog, or in jng's pseudocode language) and functional programming in languages like Haskell or ML.
awj · 2012-01-09
They are, until someone makes a five parameter monster because "someday I'll want that genericity." To be honest, though, I just googled the extensions I could remember until I hit one that hinted at creating a situation where the compiler simply doesn't have enough information to compile your code. That said, yeah, UndecidableInstances look like a much better example. Especially when googling it turns up things like this: http://lukepalmer.wordpress.com/2008/04/08/stop-using-undecidable-inst…
ionfish · 2010-04-16
No way to move files between repositories and retain their history. Luke Palmer talked about this a little here: http://lukepalmer.wordpress.com/2008/11/12/sketch-of-udon-version-cont…
hermod · 2020-08-06
In fact, yes! This is counterintuitive if you think of the floats as a model for the reals, but in fact the floats give the wrong intuition, being (a finite subset of) rationals. [1] details this and refers to two related articles (particularly [2], which I find a lighter read). This fact is also remarked on in [3] (by example of the signum function being uncomputable). For the particular example of a step function, consider the function f which is 1 on the positive reals (>=0) and 0 otherwise. What representation of the real numbers would you choose for the computation of f(0) to terminate in a finite amount of time? It cannot be the binary representation, as those are infinite. Your algorithm, terminating in a finite amount of time, will have checked only a finite number N of binary digits of the argument, and so I can choose x = 0.0{..N..}01 and obtain f(0) = f(x) by this algorithm, which is incorrect. You can choose the Cauchy sequence representation, or the Dedekind cut one, but this problem will persist (and [1] proves this in general). You can "cheat" by saying that the leading two bits will store the sign of the number: 00 for 0, 01 for positive numbers and 10 for negative ones. But then suddenly arithmetic operations are not computable (see comments on [2])! [1] https://lukepalmer.wordpress.com/2008/08/11/all-functions-are-continuo… [2] http://math.andrej.com/2006/03/27/sometimes-all-functions-are-continuo… [3] Vereshchagin, N., Shen, A. Computable…
pinopinopino · 2020-04-29
Do notation is jokingly called a programmable semicolon. True, it is often used to model imperative computations with it, so that is the association people have with it. Also people come mostly from imperative backgrounds and look, we can bind something to a value. Finally something I get! And that is fine, let them play around with it like that. But if they look closer, they find out it is not really imperative. Why is there a difference between let and bind? Why can't I reassign values. And they start to use more exotic and also more interesting monads and boom the imperative feel goes away. For example with the interesting LogicT[1] monad. Or what about the probability monad[2]? Or the continuation monad[3]? Or the reverse state monad[4]? How imperative are those really? It really depends how you use it. And I think it adds more to the magic, that you think it is just imperative code at first, because suddenly you can create code that behave very different under various monads that represent computation models. I think that is a cool thing about this confusion. I understand that if you are a professional that needs to get work done, it can be annoying. [1]https://hackage.haskell.org/package/logict [2]https://hackage.haskell.org/package/probability [3]https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Cont.… [4]https://lukepalmer.wordpress.com/2008/08/10/mindfuck-the-reverse-state…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close