[MLton-devel] phantom types and directed graphs

Stephen Weeks MLton@mlton.org
Mon, 10 Feb 2003 22:44:20 -0800


> Right, and my point is that in that world, any function that wants to deal
> with a directed graph MUST be polymorphic since it could never be monomorphic
> and handle a type involving the phantom type in a node.  This means that those
> functions have to be let-bound.

I don't agree completely.  If you want a function that deals with an
arbitrary graph, e.g. transpose, then yes, it is polymorphic.  But if
you can also have a function that is monomorphic and deals with a
specific graph type.  See sameSize and addNode in the following.

functor F (G: DIRECTED_GRAPH) =
   struct

      datatype t = T
      val g: t G.t = G.new ()
      val n = G.newNode g

      datatype u = U
      val (g': u G.t, {destroy, newNode}) = G.transpose g
      val _ = newNode n

      fun sameSize (g: 'a G.t, g': 'b G.t): bool =
	 length (G.nodes g) = length (G.nodes g')

      fun addNode (g: t G.t): unit = (G.newNode g; ())
   end


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel