Skip to content

Instantly share code, notes, and snippets.

@dohzya
Last active August 29, 2015 14:08
Show Gist options
  • Save dohzya/cda8f97f43b2e4bff9e7 to your computer and use it in GitHub Desktop.
Save dohzya/cda8f97f43b2e4bff9e7 to your computer and use it in GitHub Desktop.
Is it possible to defer a type declaration in Scala?
type Store[A, B] = (A => B) => B
def store[A, B](a: A): Store[A, B] = (x: A => B) => x(a)
// This version does not compile (returns A instead of B):
// def get[A, B](s: F[A, B]) = s(identity)
// There is a version which works, but which is kind of useless:
def get[A](s: Store[A, A]) = s(identity)
// This version does not compile (returns Int instead of Nothing)
// because of the previous get() definition:
// get( store(1) )
// We have to defined the types used by get() when invoking store():
get( store[Int, Int](1) )
//
// How can we defer the B type until the call of get()?
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment