[Haskell-cafe] Trouble understanding records and existential types
John Ky
newhoggy at gmail.com
Thu Jan 25 08:32:18 EST 2007
Let me try this option and see how I go.
Thanks
-John
On 1/25/07, Brandon S. Allbery KF8NH <allbery at ece.cmu.edu> wrote:
>
> > (b) I think you *can* do this with a class:
> >
> > class Node a where
> > name :: a -> String
> >
> > data Branch = Branch { brName :: String, ... }
> > data Leaf = Leaf { lName :: String, ... }
> >
> > instance Node Branch where
> > name = brName
> >
> > instance Node Leaf where
> > name = lName
> >
> > Okay, though it's a lot more wordy.
>
> How so? You were declaring the class and instances anyway; I simply
> defined a new method to go into it and renamed the constructor fields
> to obey Haskell's rules, but you will probably be using the class
> method so your code won't care about the latter.
>
> --
> brandon s. allbery [linux,solaris,freebsd,perl] 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 --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070126/3e815299/attachment.htm
More information about the Haskell-Cafe
mailing list