Forums / Blog

RSS
Forums » Forum Blog

Welcome to Marakana TechTalk - a set of forums where we provide code examples, software tutorials, screencasts and other educational resources. We hope you find it useful.

March 31, 2012 9:43:58 AM PDT (one year ago)
[3,943 views] [2 replies]
Photo Dan Rosen
Member since Nov 1, 2011
Location: Oakland
Forum Posts: 2
So you've got some type that takes multiple type parameters, like:

Code:
trait State[S, A]


... and you've got some code that needs to fix one of the type parameters while letting the other(s) vary. We usually use the "type lambda trick" to partially apply type arguments, like this:

Code:
def stateMonad[S] = new Monad[({type L[A] = State[S, A]})#L] { ... }


Sometimes you see this written with actual Greek characters using Unicode, where "L" is written as a lower case lambda, hence the name. Using Greek letters in source code is for jerks, unless you happen to actually be Greek, in which case go for it. However, even with the Latin "L" I don't find this style of code particularly readable, when some type lambda needs to be given a name and referenced more than once. So I propose the following new convention:

Code:
def stateMonad[S] = {
type `State[S]`[A] = State[S, A]
new Monad[`State[S]`] { ... }
}


The backticks permit use of the special [] characters which wouldn't otherwise be allowed in an identifier. At any rate, the idea is to mimic the appearance of multiple type parameter lists without yet having them in the Scala language.More...
Edited 2 times. Last edit by Dan Rosen on Mar 31, 2012 at 9:43:58 AM (about one year ago).
February 6, 2012 1:24:15 PM PST (one year ago)
[2,689 views] [no replies]
Photo Max Walker
Digital Creative Lead
Marakana, Inc.
Member since Sep 29, 2010
Location: San Francisco
Forum Posts: 10
Two quick announcements. First off, last week we kicked off Android Bootcamp Series 2012 - the definitive guide to getting started with Android development. We'll be releasing a new video tutorial every weekday.

Secondly, we've recently launched an alpha version of Marakana Stream, an easier way (hopefully) for you to browse through our ever-expanding library of educational content on open source development.

Summary: go check out Android Bootcamp Series 2012 at Marakana Stream


More...