[Haskell-cafe] 'data' syntax - a suggestion
westondan at imageworks.com
Thu Sep 27 18:28:22 EDT 2007
Thomas Conway wrote:
> Although Richard's proposal was simpler, I reckon it's worth
> discussing whether the where clause should allow normal
> type/data/newtype declarations, effectively introducing a new scope.
> There are obviously some type variable quantification and name
> resolution issues that should yield several conference papers.
> data RelaxedTree key val
> = Leaf Bal [(key,val)]
> | Node Bal [(key,RelaxedTree key val)]
> data Bal = Balanced | Unbalanced
Is Bal visible outside data RelaxedTree? If so, why not put it at the
top level. If not, are Balanced and Unbalanced visible? If not, then
there is no way to construct a RelaxedTree. If so, then you could not
give a type annotation to x = Balanced.
> data Tree key val
> = Leaf key val
> | Node BST key val BST
> type BST = Tree key val
The type synonym example is much easier because it is effectively
syntactic sugar, and although BST is not visible, Tree key val is. But
is let allowed as well, if we want to restrict the visibility of BST to
just the Node constructor? Type synomym of a type variable OK?
data Tree key val
= let BST = key in Leaf BST val -- perversely called BST
| let BST = Tree key val in Node BST key val BST
More information about the Haskell-Cafe