Not sure if that's what you need:
data NodeF f = Node {name :: String, refs :: [f (NodeF f)]}
newtype Const a b = Const a
newtype Id a = Id a
type NodeS = NodeF (Const String)
type Node = NodeF Id
Отправлено с iPhone
Dec 12, 2010, в 20:54, Florian Weimer <[email protected]> написал(а):
> Suppose I've got some named objects which reference other objects by
> name:
>
>> data NodeS = NodeS {nameS :: String, refsS :: [String]}
>
> Through name resolution, the strings are translated to the actual
> nodes they denote:
>
>> data Node = Node {name :: String, refs :: [Node]}
>> resolve :: [NodeS] -> Map String Node
>
> NodeS and Node are quite similar, so they should probably be the same
> parametrized type. However, if I turn the type of the references into
> a type parameter, I need the type-level Y combinator to avoid an
> infinite type, and manipulating nodes turns a bit more tedious because
> of increased syntactic overhead.
>
> Is there a third choice, beyond manually expanding the type definition
> or using Y?
>
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe