🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #454

pattern abstraction

#454
From: Stephen Adams
Date: Fri, 31 Aug 1990 10:06
37 lines
1662 bytes
Does anyone know of a language that supports what I call
`pattern abstraction'.  Maybe I should called it something
else.  I will explain what I mean just now.  What I want to
know is
  (a) has this been done before
  (b) if not why?
  (c) if it has did it give rise to any special problems?

Some languages allow an identifier to be repeated in a
pattern.  The usual meaning to to constrain these parts of
the input value to be equal.  For example, the Miranda
function `after' something from the head of a list but only
if it is the specified value.

	after x (x:rest) = rest
	after x other    = other

This function is equivalent to

	after' x (x':rest) = rest, if x=x'
	after' x other     = other

If you explicitly curry the first function you break it, but
you can do this to the second version.

	after'' x = f where  f (x:rest) = rest
			     f other    = other

	after''' x = f where  f (x':rest) = rest, if x=x'
			      f other    = other

This loss of equivalence under a simple transformation could
be used as a reason to prohibit repeated identifiers in
patterns.  Alternatively, the equivalence could be enforced
by a rule requiring that pattern identifiers that are bound
in the (same|enclosing) scope mean an equality check.
Have any languages taken this route?
Technical Details
Message-ID: <3685@ecs.soton.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!icdoc!sot-ecs!sra

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!icdoc!sot-ecs!sra
From: sra@ecs.soton.ac.uk (Stephen Adams)
Newsgroups: comp.lang.functional,local.research.dsc
Subject: pattern abstraction
Message-ID: <3685@ecs.soton.ac.uk>
Date: 31 Aug 90 10:06:14 GMT
Organization: University of Southampton, UK
Lines: 37