[Haskell-cafe] Avoiding the Y combinator for self-referencing types
Miguel Mitrofanov
miguelimo38 at yandex.ru
Sun Dec 12 19:24:06 CET 2010
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 <fw at deneb.enyo.de> написал(а):
> 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
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list