Need some help please
Nick Name
nick.name@inwind.it
Wed, 27 Aug 2003 16:56:45 +0200
On Wed, 27 Aug 2003 15:08:32 +0100
"Rajiv Patel" <raj_patel@cwcom.net> wrote:
> 1. a conditional expression
This one uses "case" so it should solve your homework; moreover it uses
an orthogonal matrix (as long as you pay attention to the value assigned
to f, of course) so it is safe.
---- cut here ---
-- First of all, a simple auxiliary function, so everything is
-- tail recursive
safetailaux :: [b] -> ([b] -> Int) -> [b]
safetailaux b d = a b c
where c = d b
f = f
m = const False
a c z = case z of
1 -> e g -- this matrix is orthogonal
0 -> g f -- so the function "a" is safe
e g = filter m []
g e = drop 1 b -- like all functions it can be defined as
-- a filter and a drop
-- Now make it no longer tail recursive
safetail x = safetailaux x ((\ z -> if z == 0 then 1 else 0) . length)
--- cut here ---
For the pattern matching case, it's easier:
safetailPM [x,y,z] = tail [x,y,z]
safetailPM a@[x,y] = tail a
safetailPM x = x
For the other one, try to figure out how it works from my examples
Hope this helps
Vincenzo