What are some compelling use cases for dependent method types?

前端 未结 4 1087
慢半拍i
慢半拍i 2020-11-27 09:01

Dependent method types, which used to be an experimental feature before, has now been enabled by default in the trunk, and apparently this seems to have created some excitem

4条回答
  •  天命终不由人
    2020-11-27 09:43

    trait Graph {
      type Node
      type Edge
      def end1(e: Edge): Node
      def end2(e: Edge): Node
      def nodes: Set[Node]
      def edges: Set[Edge]
    }
    

    Somewhere else we can statically guarantee that we aren't mixing up nodes from two different graphs, e.g.:

    def shortestPath(g: Graph)(n1: g.Node, n2: g.Node) = ... 
    

    Of course, this already worked if defined inside Graph, but say we can't modify Graph and are writing a "pimp my library" extension for it.

    About the second question: types enabled by this feature are far weaker than complete dependent types (See Dependently Typed Programming in Agda for a flavor of that.) I don't think I've seen an analogy before.

提交回复
热议问题