Code: Select all

`ps2.hs:4:16: parse error on input `insertVertex'`

Can anyone tell me what this message means? I've tried removing the if-then-else portion since my prof told us it was optional and using (graph Char Int) instead of graph as a parameter, but neither worked. I also added

Code: Select all

`type v = Char`

type e = Int

to the code and v,e to the module interface given to us in the template, so if that could be causing the problem please let me know and explain why that's a problem. I'd prefer minimal help, such as an explanation of the error message or a syntax correction rather than a step by step solution, as this is for a class and I'm trying to learn these concepts. Thanks!

Code: Select all

`-- A module for creating and handling directed graphs`

module Digraph (AdjList, Digraph, Edge, v, e

insertVertex, insertEdge, makeDigraph, getAdj,

empty, vertexInGraph

) where

-- In these type declarations, v is the vertex type

-- and e is the edge label type

type AdjList v e = [(v, e)]

type Digraph v e = [(v, AdjList v e)]

type Edge v e = (v, v, e)

type v = Char

type e = Int

empty :: Digraph v e

empty = []

-- Adds a new vertex with an empty adjacency list to the digraph

insertVertex :: (Eq v) => v -> Digraph v e -> Digraph v e

insertVertex v graph = if (vertexInGraph v graph)

then error "Vertex already in graph"

else graph ++ [(v,[])]

-- Creates a list of the vertices in the graph, then checks to see if

-- any of them are the same as the given vertex, then checks for a

-- value of True in the resulting list

vertexInGraph :: (Eq v) => v -> Digraph v e -> Bool

vertexInGraph v graph = foldl || false (map (== v) (map fst graph))