<div dir="ltr"><br clear="all"><div>Hi, </div><div><br></div><div>Do I need to define indices and elem for Graph a w here explicitly ? </div><div><br></div><div><br></div><div><br></div><div><div>import Data.Array</div><div>
<br></div><div>data Graph a w = Array a [(a,w)]</div><div>-- array (1,3) [(1,[(2,3),(3,2)])]</div><div><br></div><div>--Given a vertex list out adjacents</div><div>getAdjVertices :: (Ix a, Eq a) => a -> (Graph a w) -> [a]</div>
<div><br></div><div>getAdjVertices x arr | not (x `elem` (indices arr)) = error "No such Vertex"</div><div>                     | otherwise = extractV (arr ! 2)</div><div>                     where extractV [] = []</div>
<div>                           extractV (x:xs) = (fst x):extractV (xs)</div></div><div><br></div><div>GHCI gives : </div><div><br></div><div>Prelude> :l programs\graph.hs<br></div><div><div>[1 of 1] Compiling Main             ( programs\graph.hs, interpreted )</div>
<div><br></div><div>programs\graph.hs:16:47:</div><div>    Couldn't match expected type `Array a e0'</div><div>                with actual type `Graph a w'</div><div>    In the first argument of `indices', namely `arr'</div>
<div>    In the second argument of `elem', namely `(indices arr)'</div><div>    In the first argument of `not', namely `(x `elem` (indices arr))'</div><div><br></div><div>programs\graph.hs:17:46:</div><div>
    Couldn't match expected type `Array Integer [(a, b0)]'</div><div>                with actual type `Graph a w'</div><div>    In the first argument of `(!)', namely `arr'</div><div>    In the first argument of `extractV', namely `(arr ! 2)'</div>
<div>    In the expression: extractV (arr ! 2)</div><div>Failed, modules loaded: none.</div><div>Prelude></div></div><div><br></div><div><br></div>Regards. <br>Nishant
</div>