IArray

Hal Daume III hdaume@ISI.EDU
Sun, 24 Feb 2002 23:31:15 -0800 (PST)


Just a quick follow-up that I meant to say in that last email.  For
instance, I think it would be reasonable to define tuples as instances of
a HasBounds class, but that's not possible with the current
definition.  With my definition, I'd write:

> instance HasBounds (a,b) Int where { bnds _ = (0,1) }
> instance HasBounds (a,b,c) Int where { bnds _ = (0,2) }
> etc...

On the other hand, tuples could not be considered arrays in the IArray
sense unless each element of the tuple had the same time.  We could have:

> instance IArray (a,a) a where ...

but not

> instance IArray (a,b) ...

Anyway, it's late, bed time.  :)

 - Hal

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume

On Sun, 24 Feb 2002, Hal Daume III wrote:

> After reading your email i went to the discussion of IArray on the haskell
> doc page (http://www.haskell.org/ghc/docs/latest/set/sec-iarray.html) and
> am somewhat disturbed by it.  There is the introduction of the following
> class:
> 
> > class HasBounds a where
> >   bounds :: Ix ix => a ix e -> (ix,ix)
> 
> which is then used in:
> 
> > class HasBounds a => IArray a e where
> >   array :: Ix ix => (ix,ix) -> [(ix,e)] -> a ix e
> >   (!) :: ...
> >   (//) :: ...
> 
> I'm not sure what's bothering me about this, except that this HasBounds
> declaration seems to be "anticipating" the IArray declaration.  That the
> type of the bounds function assumes that for this type "a" which "has
> bounds", there are two associated types, the index type and the element
> type, seems to be reading too much into what it means to have bounds.  A
> more reasonable (imo) definition would be:
> 
> > class Ix ix => HasBounds a ix | a -> ix where
> >   bounds :: a -> (ix,ix)
> 
> that way, we would efine things like:
> 
> > instance Ix ix => HasBounds (Array.Array ix) ix where ...
> > instance Ix ix => HasBounds (UArray ix) ix where ...
> 
> I think this makes things much cleaner (arguably it makes these instance
> declarations a bit longer, but it makes HasBounds a class in its own
> right; as it is, I don't see any reason why HasBounds should be its own
> class and why the 'bounds' function isn't simply lumped into the IArray
> class).
> 
> Of course, this require dep types, which is unfortunate, but then again,
> anyone who is using IArrays probably isn't writing Haskell 98 anyway, and
> every compiler supports dep types, so... ;)
> 
> On the other hand, if using dep types is opposed, I would be in favor of
> getting rid of the HasBounds class and lumping the bounds function into
> IArray.
> 
> Of course, that's just my opinion... :)
> 
>  - Hal
> 
> --
> Hal Daume III
> 
>  "Computer science is no more about computers    | hdaume@isi.edu
>   than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
> 
> On Fri, 22 Feb 2002, David Feuer wrote:
> 
> > What is IArray?  This seems rather mysterious to me.
> > 
> > David Feuer
> > _______________________________________________
> > Glasgow-haskell-users mailing list
> > Glasgow-haskell-users@haskell.org
> > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
> > 
> 
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users@haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>