Apocalisp

apocalisp.wordpress.com · Personal blog · on HN since 2008

Runar Bjarnason writes about functional programming, type systems and Scala, with posts on Java, Haskell-style iteratees and type theory.

What HN saysHN commenters link his post that the Liskov Substitution Principle is contravariance, and his structural pattern matching in Java as a pattern for avoiding isinstance checks.
23HN people shared it
10linked it in comments
13stories submitted
134story points
2 years agolast shared
2008people per year2026

Most-shared posts

  1. 1
    Structural Pattern Matching in Java
    4 people · 8 points · first shared 2009 · 1 comments on HN
  2. 2
    Liskov Substitution Principle is Contravariance (2010)
    4 people · 4 points · first shared 2013 · discussion on HN
  3. 3
  4. 4
  5. 5
    Imperative vs Functional Programming
    1 people · 81 points · first shared 2011 · 66 comments on HN
  6. 6
    Arguments in favor of pure functional programming
    1 people · 32 points · first shared 2009 · 21 comments on HN
  7. 7
  8. 8
    Noumenal Null: Null vs. Pure Reason
    1 people · 1 points · first shared 2008 · discussion on HN
  9. 9
    Objects, Identity, and Concept-Formation
    1 people · 1 points · first shared 2012 · discussion on HN
  10. 10
    Towards an Effect System in Scala, Part 2: IO Monad
    1 people · 1 points · first shared 2011 · discussion on HN
  11. 11
    Type level programming in scala
    1 people · first shared 2013
  12. 12
  13. 13
    A proper constant function in scala
    1 people · first shared 2012
  14. 14
    Thrower functor
    1 people · first shared 2012
  15. 15
    Higher rank polymorphism in scala
    1 people · first shared 2014

What HN people wrote when they linked it

pka · 2012-07-02
So, Java's HashMap.get() should throw a checked exception whenever the value is not found in the map? That would sure eliminate a lot of boilerplate code :) Aren't exceptions meant to be used for, well, exceptional cases only, i.e. when no matter what, execution really can't be continued? It makes sense for a lot of functions to return some sort of "Nothing" value instead of raising an exception, but the problem is that in many languages there is no explicit "Nothing" value, so people just abuse null. You can have Maybe in Java too, but getting out a value or a Nothing out of a Maybe value is just not enforced by the compiler due to the lack of algebraic data types and pattern matching; still, it is an improvement over null hell. On a side note, Maybe is called Option in Scala. By the way, exceptions are monads, they are just predefined in most languages in a way you can not change. If you want a lengthy Java centric read about that I would strongly recommend checking out [1]. Ant here's another if you're ok with reading Haskell [2]. Also for the record, in Haskell you can use the ErrorMonad in place of the Maybe monad if you want precise error reporting capabilities. [1] http://apocalisp.wordpress.com/2008/05/16/thrower-functor [2] http://www.haskell.org/haskellwiki/Exception
bts · 2025-01-21
And functional programmers would argue that contravariance is the real meaning of Liskov’s substitution principle: https://apocalisp.wordpress.com/2010/10/06/liskov-substitution-princip…
tiew9Vii · 2022-03-29
This may be a useful pattern to you. The example is in Java but you should be able to achieve the same in Python https://apocalisp.wordpress.com/2009/08/21/structural-pattern-matching… It’ll get rid of the ‘isinstance’ and give exhaustive matching. I used to use this pattern a lot when wanting ADT’s in a language without ADT’’s.
platz · 2015-01-22
apparently LSP is just a contravariant functor https://apocalisp.wordpress.com/2010/10/06/liskov-substitution-princip… But I don't see how the relationship of contravariant functors to OO-style subclasses is as clear as the DI <-> function abstraction example (functions are just functions in OO or FP)
gclaramunt · 2013-12-02
yes, it can. It ugly, because you're doing type level programming, but is possible http://apocalisp.wordpress.com/2010/06/08/type-level-programming-in-sc…
Peaker · 2012-01-10
Well, Scala has advantages and disadvantages over Haskell, but I wouldn't say it is more "powerful" than Haskell. Consider the implementation of a properly lazy "const" function in Haskell: const x _ = x And in Scala: http://apocalisp.wordpress.com/2010/04/21/a-proper-constant-function-i… Not sure about Coq, but Agda is Turing Complete (you just need to turn off termination checks) and Epigram also supports general recursion as well as structural recursion with total functions.
trurl · 2011-11-22
Yes, you can do that by using types indexed by a number. See https://apocalisp.wordpress.com/2010/06/16/type-level-programming-in-s… for one take on this.
fhars · 2011-11-22
That is not a simple type. And people who still remember the original Pascal will know that you do not want to encourage people to make the size part of the collection type. And it doesn't buy you much if you cannot prove at compile time that the type you use to index into the collecton cannot overflow the collection bounds. Use Ada if you need that. But if you want you can also encode the sizes in binary or decimal numbers: http://apocalisp.wordpress.com/2010/06/24/type-level-programming-in-sc… http://www.ict.kth.se/forsyde/files/tutorial/apas03.html
narrator · 2010-06-16
When I get a compiler error in Scala it's almost always something that would cause a runtime error in a non statically typed language. The downside is that the error messages can be difficult to parse and resolve for beginners. Once I got over the learning curve, I realized that in almost all cases the compiler was trying to tell me something very useful. I do get a little annoyed at all the Haskell/OCaml type nerds trying to do things with the type system that are not particularly practical, for instance: http://apocalisp.wordpress.com/2010/06/16/type-level-programming-in-sc…

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