aaron.harnly.net http://harnly.net Sì, abbiamo un'anima. Ma è fatta di tanti piccoli robot. Thu, 07 Aug 2008 04:59:59 +0000 http://wordpress.org/?v=abc en What I’ve been up to on 2008-08-06 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/#comments Thu, 07 Aug 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/
  • wants to ride in an A380 just for the Tailcam. #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-06/feed/
    What I’ve been up to on 2008-08-04 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/#comments Tue, 05 Aug 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/
  • wondering whether cherries would be as delicious if they were the size of plums. Would they be too strong? Or the best thing ever? #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-04/feed/
    What I’ve been up to on 2008-08-01 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/#comments Sat, 02 Aug 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/
  • so happy there’s going to be an official “garfield minus garfield” book. Jim Davis must be cooler than I’ve given him credit for. #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-08-01/feed/
    What I’ve been up to on 2008-07-22 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/#comments Wed, 23 Jul 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/
  • is wrestling with cyclic reference errors, and feels like a cyclic reference error himself. #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-22/feed/
    What I’ve been up to on 2008-07-19 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/#comments Sun, 20 Jul 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/
  • has been watching 90 minutes of 30 Rock every night. I think this TV thing might catch on. #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-19/feed/
    Lazy vals with implicit parameters http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/ http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/#comments Thu, 17 Jul 2008 15:04:54 +0000 aaronharnly http://harnly.net/?p=176 Lazy vals were an excellent addition to Scala 2.6.0. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached.

    Unfortunately, this doesn’t play so well with another wonderful Scala feature — implicit parameters. It’s often the case that you’ll want to defer resolution of an implicit until a method call, rather than in the scope of object creation. But lazy values cannot take any parameters, implicit or otherwise — so it seems you’re stuck.

    Memoized to the rescue! This is a simple helper class that takes care of the caching of a result. Where you might have had the following method with an implicit parameter:

    def foo(implicit bar: Bar): ResultType = { ... }

    you instead write the following:

    private var _foo = Memoized[ResultType]
    def foo(implicit bar: Bar) = _foo or { ... }

    (complete source below the fold)

    That’s it; nothing fancy. This is not a true memoization solution for a function that takes a parameter — check out the memo package in Scalaz for that. But I’ve found it handy, and you might too.

    class Memoized[T] {
    	private var value: Option[T] = None
    	def isEmpty = value.isEmpty
    	def isDefined = ! isEmpty
    	def get: T = value.get
    	def set(newValue: T) { value = Some(newValue) }
    	def getOrSet( newValue: => T): T = if (isDefined) get else {
    		set(newValue)
    		get
    	}
    	def or( newValue: => T): T = getOrSet(newValue)
    	override def toString = value.toString
    }
     
    object Memoized {
    	def apply[T] = new Memoized[T]
    }
    ]]>
    http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/feed/
    What I’ve been up to on 2008-07-14 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-14/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-14/#comments Tue, 15 Jul 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-14/
  • is in the office, looking forward to a fried green tomato/pita sandwich. #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-07-14/feed/
    What I’ve been up to on 2008-06-26 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-26/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-26/#comments Fri, 27 Jun 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-26/
  • going on a yoga retreat in Mexico. Yes, really. Yes, Aaron Harnly. And I’m very excited about it! #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-26/feed/
    What I’ve been up to on 2008-06-25 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-25/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-25/#comments Thu, 26 Jun 2008 04:59:59 +0000 twitterbot http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-25/
  • I’ve got to stop putting off conditional random fields. #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-25/feed/
    What I’ve been up to on 2008-06-11 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-11/ http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-11/#comments Thu, 12 Jun 2008 04:59:59 +0000 http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-11/
  • gonna build a grubstake by minstrelsy. #
  • ]]>
    http://harnly.net/2008/blog/autobiography/what-ive-been-up-to-on-2008-06-11/feed/