[Haskell-cafe] List implementation.

MR K P SCHUPKE k.schupke at imperial.ac.uk
Tue Oct 12 08:59:17 EDT 2004


Hows this:

...
   tail (Many i a l)
      | i < (e-s) = (Many (i+1) a l)
      | otherwise = l
      where (s,e) = bounds a
...
      a ++: l
      | e >= s = Many s a l
      | otherwise = l
      where (s,e) = bounds a

A futher though is that with constructors you can do:

	f (a:as) =
	f [] =

As you cannot use the constructors to access the list elements here,
maybe the following would be more useful:

class List l where
   head :: IArray UArray a => l a -> Maybe a
   tail :: IArray UArray a => l a -> Maybe (l a)

then you can write:

	f x
	 | Just h <- head x = ...
	 | otherwise = ...



	Keean.


More information about the Haskell-Cafe mailing list