converting capital letters into small letters

Garner, Robin Robin.Garner@crsrehab.gov.au
Fri, 26 Jul 2002 17:27:49 +1000


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C23475.F1EB68B0
Content-Type: text/plain;
	charset="iso-8859-1"

> 1. How would I convert capital letters into small letters?
> 
> 2. How would I remove vowels from a string?

I expect the first problem is actually to convert the upper case letters in
a string to lower case, as the single-character version isn't a very
interesting problem.

A little thought shows that the first problem can be expressed as both a
catamorphism or an anamorphism.  The anamorphic solution would be [(p,f)]
where 
    p as = as == [] and 
    f (a:as) = (makeLowerCase a, bs).

The solution to the second problem is clearly a catamorphism, and one
solution might be (|[],g|) where
    g (a:as) = if isVowel a then as else a:as

The definitions of 'makeLowerCase' and 'isVowel' are quite simple (assuming
English/Ascii, as pointed out in other messages), while finding the prelude
functions for the patterns of recursion might take a little more thought.
Suitable, possible, as homework questions in an introductory Haskell course
...

Robin

------_=_NextPart_001_01C23475.F1EB68B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>RE: converting capital letters into small letters</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>&gt; 1. How would I convert capital letters into =
small letters?</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; 2. How would I remove vowels from a =
string?</FONT>
</P>

<P><FONT SIZE=3D2>I expect the first problem is actually to convert the =
upper case letters in a string to lower case, as the single-character =
version isn't a very interesting problem.</FONT></P>

<P><FONT SIZE=3D2>A little thought shows that the first problem can be =
expressed as both a catamorphism or an anamorphism.&nbsp; The =
anamorphic solution would be [(p,f)] where </FONT></P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; p as =3D as =3D=3D [] and </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; f (a:as) =3D (makeLowerCase a, =
bs).</FONT>
</P>

<P><FONT SIZE=3D2>The solution to the second problem is clearly a =
catamorphism, and one solution might be (|[],g|) where</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; g (a:as) =3D if isVowel a then as =
else a:as</FONT>
</P>

<P><FONT SIZE=3D2>The definitions of 'makeLowerCase' and 'isVowel' are =
quite simple (assuming English/Ascii, as pointed out in other =
messages), while finding the prelude functions for the patterns of =
recursion might take a little more thought.&nbsp;&nbsp; Suitable, =
possible, as homework questions in an introductory Haskell course =
...</FONT></P>

<P><FONT SIZE=3D2>Robin</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C23475.F1EB68B0--