[Haskell-beginners] Typeclasses and "inheritance"

Patrick LeBoutillier patrick.leboutillier at gmail.com
Fri Jul 24 15:03:34 EDT 2009


>
> >   -- Takes an IPAddr and returns another one describing the network
> >   subnet :: (Word (Host a) ~ Word (Mask a)) => a -> a
> >   subnet a = let m = mask a
> >                  h = host a
> >              in makeIPAddr (fromBits $ (bits h) .&. (bits m)) $ m


Excellent!


> Note that I didn't put a IPAddr context since in your code subnet is a
> method of this class (with a default implementation), if this wasn't
> your intention you should correct the indentation.


You are right, the context was not necessary. The function is in fact a
default implementation.

BTW: Does what I'm trying to do make any sense at all? Does anyone know of a
better/simpler way to do this (i.e making most of these computations
independant of the exact underlying type)?


Anyways, thanks a lot for your help,

Patrick



>
> --
> Jedaï
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090724/e814bf4d/attachment.html


More information about the Beginners mailing list