Hacker News new | ask | show | jobs
by ch 3829 days ago
What is really cool about this approach is that, unlike the counterpart design patterns you might find in an imperative OO language such as the Interpreter and Command patterns, within the strong-statically-typed functional languages we can rely on the guarantees the type system gives us for abstractions such as the Free Applicative to allow for optimizations that would be merely convention in a less type-enforcing type system.
1 comments

Some `design patterns' are expressible even in very weak type systems.

For example, array of tuples vs tuple of arrays. In pseudo Haskell notation:

:: ([a], [b], [c])

:: [(a, b, c)]

The second option enforces that you have the same number of a's, b's and c's. The second option can be faster to access in, say, C.

(I wonder whether you can do a similar, but more complicated, analysis for internal vs external linked lists and other containers.)