[Haskell-beginners] Error while using indices and elem

Chaddaï Fouché chaddai.fouche at gmail.com
Mon Apr 21 09:26:34 UTC 2014


On Mon, Apr 21, 2014 at 10:06 AM, Nishant <nishantgeek at gmail.com> wrote:

>
> 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)])]
>
>
>
You probably meant to make "Graph a w" a type synonym but you used "data"
thus it is a type constructor with one data constructor named Array which
takes two parameters : an "a" and a list of pairs of "a" and "w".
You wanted to write :

> type Graph a w = Array a [(a,w)]

which should work better (indices will work on it like on an Array from
Data.Array).

-- 
Jedaï
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140421/5d1a8b65/attachment.html>


More information about the Beginners mailing list