[Haskell-beginners] Error while using indices and elem
Nishant
nishantgeek at gmail.com
Mon Apr 21 08:06:19 UTC 2014
Hi,
Do I need to define indices and elem for Graph a w here explicitly ?
import Data.Array
data Graph a w = Array a [(a,w)]
-- array (1,3) [(1,[(2,3),(3,2)])]
--Given a vertex list out adjacents
getAdjVertices :: (Ix a, Eq a) => a -> (Graph a w) -> [a]
getAdjVertices x arr | not (x `elem` (indices arr)) = error "No such Vertex"
| otherwise = extractV (arr ! 2)
where extractV [] = []
extractV (x:xs) = (fst x):extractV (xs)
GHCI gives :
Prelude> :l programs\graph.hs
[1 of 1] Compiling Main ( programs\graph.hs, interpreted )
programs\graph.hs:16:47:
Couldn't match expected type `Array a e0'
with actual type `Graph a w'
In the first argument of `indices', namely `arr'
In the second argument of `elem', namely `(indices arr)'
In the first argument of `not', namely `(x `elem` (indices arr))'
programs\graph.hs:17:46:
Couldn't match expected type `Array Integer [(a, b0)]'
with actual type `Graph a w'
In the first argument of `(!)', namely `arr'
In the first argument of `extractV', namely `(arr ! 2)'
In the expression: extractV (arr ! 2)
Failed, modules loaded: none.
Prelude>
Regards.
Nishant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140421/e6a0e9a0/attachment.html>
More information about the Beginners
mailing list