Thanks for the plug. I would really appreciate if anyone has comments
or criticisms to make.
Also, I was wondering if there is any way to remove the boilerplate
from the code. It becomes apparent when looking at the version with
abstract members (
http://snippets.dzone.com/posts/show/5741).
Leaving aside the phantom types, it is easy to define a BuilderPart
class to encapsulate each field (a thin wrapper over Option[] that
returns the builder for method chaining); the price is a little
mutable state. But when the types are added to the picture, I can't
think of a way to avoid threading them all in each builder method.
Moreover, when threading the types, I couldn't find a way to avoid
threading the values as well.
PS: Curiously, when looking around for a solution to avoid threading
the values, I implemented a pseudo-dependent Map very similar to the
one Sean proposed earlier today. Just an amusing coincidence :)
PS2: No grains of barley were harmed in the writing of the blog post.
On Wed, Jul 9, 2008 at 2:08 PM, James Iry <
jamesiry@...> wrote:
> Here's somebody having fun (and getting drunk) with Scala's type system:
>
>
http://blog.rafaelferreira.net/2008/07/type-safe-builder-pattern-in-scala.html>
--
Rafael de F. Ferreira.
http://www.rafaelferreira.net/