Field labels must be globally unique?
John Meacham
john@repetae.net
Tue, 7 Jan 2003 20:25:55 -0800
a plausable workaround in haskell 98 is to use a typeclass like so
class EdgyNodelike a where
node :: a -> Int
edge0 :: a -> a
edge1 :: a -> a
instance EdgyNodelike BFSM where
node = bfsmnode
edge0 = bfsmedge0
edge1 = bfsmedge1
instance EdgyNodelike BMC where
node = bmcnode
edge0 = bmcedge0
edge1 = bmcedge1
that will let you write code which works on anything with edges or
nodes.
John
On Tue, Jan 07, 2003 at 10:01:38PM -0600, Kim-Ee Yeoh wrote:
> Dear Haskellers,
>
> Why can't field labels have the same name in different types?
>
> Here's some actual code on finite state automata I'm working on:
>
> > data BMC
> > = BMC { node :: !Int,
> > threshold :: !Float,
> > edge0 :: BMC,
> > edge1 :: BMC }
>
> > data BFSM
> > = BFSM { bfsmnode :: !Int,
> > bfsmstate :: Maybe Bool,
> > bfsmoutput :: [Bool],
> > bfsmedge0 :: BFSM,
> > bfsmedge1 :: BFSM }
>
> What I really want is to use the same field labels of node, edge0, and
> edge1 in the BFSM type, but I can't because otherwise I get the following
> in hugs:
>
> ERROR xxx - Repeated definition for selector "edge0"
>
> I'm not an expert on programming languages, but doesn't it seem
> that Haskell, as a strongly-typed language, should not have any problem
> distinguishing the field labels of different datatypes?
>
>
> Kim-Ee
>
>
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
--
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john@foo.net
---------------------------------------------------------------------------