Proposal: pattern synonyms
Henrik Nilsson
nhn at Cs.Nott.AC.UK
Thu Feb 16 08:54:44 EST 2006
Dear all,
Conor wrote:
> You forgot to define the term behaviour also. Pattern synonyms may be
> used to construct as well as to match values.
Conor and I discussed this over lunch.
Specifically, we talked about whether the right hand side of a pattern
synonym would be any Haskell pattern (including "_", "~", possibly "!"),
or restricted to the intersection between the patterns and terms, as
Conor propose that pattern synonyms also be used for construction.
By adopting some simple conventions, like replacing "_" by "undefined"
when a synonym is used as a term for construction, it is clear that one
can be a bit more liberal than a strict intersection between the pattern
and current expression syntax.
Incidentally, this would be consistent with the way record patterns
and record construction currently works. E.g.
data Foo = MkFoo {l1 :: T1, l2 :: T2}
A pattern "MkFoo {}" expands to "MkFoo _ _", a term "MkFoo {}" expands
to "MkFoo undefined undefined".
Moreover, didn't someone (John Mecham?) propose that "_" be a valid
term anyway, standing for "undefined" (with an explicit requirement
of keeping track of the source code position)?
Maybe "~" (and "!") wouldn't cause much trouble either.
I like the idea, but it would be nice if the RHS of a pattern
synonym definition really coudl be any Haskell pattern, without any
additional restriction (except that it has to be acyclic).
All the best,
/Henrik
--
Henrik Nilsson
School of Computer Science and Information Technology
The University of Nottingham
nhn at cs.nott.ac.uk
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
More information about the Haskell-prime
mailing list