[clean-list] Problem overloading <<< for lists

a.v.w@hccnet.nl a.v.w@hccnet.nl
Fri, 22 Aug 2003 15:24:52 UT


This is a multi-part message in MIME format.

--_----------=_106156589298066
Content-Disposition: inline
Content-Length: 1698
Content-Transfer-Encoding: binary
Content-Type: text/plain

Hello Ge,

In Clean instances must all be different at the outermost type. Both instances in your example are lists, hence the error. Very annoying, I agree. I usually solve this by introducing a new class (instead of a new type) for the outermost type (lists, in this case, often it's arrays). I think the compiler could do this automatically, if someone implemented it.

class writeList a :: !*File ![a] -> *File

instance writeList Int //your code for instance <<< [Int]

instance writeList Real //your code for instance <<< [Real]

instance <<< [a] | instance writeList a
where
  (<<<) f list = writelist f list

regards,
  Arjen

> 
> Hello all,
> 
> I'm trying to implement writing a list to file, and I want the behaviour
> to depend on the type of the elements in the list, like:
> 
> module tst
> 
> import StdFile
> 
> instance <<< [Int]
> where
>   (<<<) :: !*File ![Int] -> !*File
>   (<<<) f _ = f
> 
> instance <<< [Real]
> where
>   (<<<) :: !*File ![Real] -> !*File
>   (<<<) f _ = f
> 
> Start :: !*World -> *World
> Start world
> # (cons, world) = stdio world
> # cons = cons <<< [1,2,3] <<< "\n"
> # (ok, world) = fclose cons world
> = world
> 
> 
> Trying to compile this gives (Clean 2.0.2, Linux x86)
> 
> Error [tst.icl,5,<<<]:multiply defined
> 
> So it looks like the compiler ignores the type of the list elements.
> Does anyone have a clue as to how to resolve this? (apart from
> introducing
> a new, abstract type, I mean)
> 
> Thanks,
> 
>> 
> 
> 
> _______________________________________________
> clean-list mailing list
> clean-list@cs.kun.nl
> http://www.cs.kun.nl/mailman/listinfo/clean-list


--_----------=_106156589298066--