[Haskell-cafe] Abstraction in data types

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Thu Mar 18 01:48:09 EDT 2010


On Mar 18, 2010, at 01:27 , Darrin Chandler wrote:
> On Thu, Mar 18, 2010 at 01:06:25PM +0800, Lyndon Maydwell wrote:
>> You could probably also use a typeclass for pointy things rather than
>> a data type, this would then require you to use existential
>> quantification to construct a hetrogenous list.
>
> So in "normal" use Polygon list would be homogeneous, but could be  
> made
> heterogeneous with effort? If I have that right it's closer, but I'd
> love to have the compiler whine if someone tried to mix them.

They can be mixed only with significant effort.  And you can't really  
prevent it once your users know the magic of existential  
quantification; *but* those lists won't typecheck when passed to your  
routines expecting a Polygon, because you will be expecting a (Point a  
=> Polygon [a]) but they will be passing a (Polygon [forall a. Point a  
=> a]) or something similar.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100318/27239ed6/PGP.bin


More information about the Haskell-Cafe mailing list