Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deanwampler/87acafa601017b5671c95875422500d0 to your computer and use it in GitHub Desktop.
Save deanwampler/87acafa601017b5671c95875422500d0 to your computer and use it in GitHub Desktop.
// Adapted from:
// https://github.com/deanwampler/programming-scala-book-code-examples/blob/master/src/script/scala/progscala3/typesystem/deptypes/DepMethodFunc.scala
scala> trait LinkedList:
| type Item // abstract type alias
| def head: Item
| def tail: Option[LinkedList]
scala> def head(ll: LinkedList): ll.Item = ll.head // dependent method type for the return value.
| val h: (ll: LinkedList) => ll.Item = _.head // dependent function type for the return value (not supported in Scala 2)
| def tail(ll: LinkedList): Option[LinkedList] = ll.tail // similar...
| val t: (ll: LinkedList) => Option[LinkedList] = _.tail // similar...
def head(ll: LinkedList): ll.Item
val h: (ll: LinkedList) => ll.Item = Lambda$7945/0x0000000801d950d8@7e573edd
def tail(ll: LinkedList): Option[LinkedList]
val t: (ll: LinkedList) => Option[LinkedList] = Lambda$7946/0x0000000801d954a8@2a1e947a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment