hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Basic Graph structure

Last post 05-09-2007, 8:42 by dsyme. 2 replies.
Sort Posts: Previous Next
  •  05-08-2007, 7:21 3102

    Basic Graph structure

    I am attempting to design a class to use as a basis for general purpose graphs.  my basic design looks as follows:

    type 'a graph_edge = class

    val from_node : 'a Option

    val to_node : 'a Option

    new () = { from_node = None; to_node = None; }

    new (from_n : 'a, to_n:'a) = { from_node = Some from_n; to_node = Some to_n; }

    end

    type ('a, #graph_edge<'a>) graph_base = class

    val nodes : 'a array

    val edges : #graph_edge<'a> array

    end

     

    where graph_edge holds references to the from and to object and derived classes of graph_base must define a class for the nodes and a class based on graph_edge for the edges.  However I am getting a syntax error on the declaration of the second type parameter to graph_base when I add the pound sign to indicate that classes based on graph_edge are acceptable.  What am I doing wrong here?

     

    David

  •  05-08-2007, 7:49 3103 in reply to 3102

    Re: Basic Graph structure

    I have found a construct that seems to work.  At least I am getting no syntax errors when using it. 

    type ('a, 'b)graph_base when 'b :> graph_edge<'a> = class

    val nodes : 'a array

    val edges : 'b array

    end

    I have a question the dreaded syntax error is extremely uninformative.  is it possible to enhance the compiler error reporting so that when a syntax error occurs the actual syntactical law that is being violated could be cited?

     

    Thanks David

     

  •  05-09-2007, 8:42 3116 in reply to 3103

    Re: Basic Graph structure

    Hi David,

    We can improve the error messages on a case by case basis by adding rules to the grammar. Please drop us a bug report to fsbugs AT microsoft DOT com each time you see and error message that looks like it can be improved.

    thanks!

    don

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems