hpaste1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| buildTable :: Int -> Int -> (Int -> Int -> a) -> [[a]]
buildTable n m fun = [[ fun x y
| x <- [0..n1]]
| y <- [0..m1]]
lookupAns :: Int -> Int -> [[Int]] -> Int
lookupAns len1 len2 theArray =
theArray !! len1 !! len2
lcsLength :: String -> String -> Int
lcsLength s1 s2 =
let
n1' = (length s1)
n2' = (length s2)
table = buildTable n1' n2' lcsHelp
lcsHelp n1 n2 = if ( n1 == 0 || n2 == 0 )
then 0
else if ( last s1 == last s2 )
then
(lookupAns (n1 1) (n2 1) table) + 1
else
max (lookupAns n1 (n21) table) (lookupAns (n11) n2 table)
in lookupAns (length s1) (length s2) table
|
20:5: Warning: Use guards
Found:
lcsHelp n1 n2
= if (n1 == 0 || n2 == 0) then 0 else
if (last s1 == last s2) then
(lookupAns (n1 - 1) (n2 - 1) table) + 1 else
max (lookupAns n1 (n2 - 1) table) (lookupAns (n1 - 1) n2 table)
Why not:
lcsHelp n1 n2
| (n1 == 0 || n2 == 0) = 0
| (last s1 == last s2) = (lookupAns (n1 - 1) (n2 - 1) table) + 1
| otherwise =
max (lookupAns n1 (n2 - 1) table) (lookupAns (n1 - 1) n2 table)
20:21: Warning: Redundant bracket
Found:
if (n1 == 0 || n2 == 0) then 0 else
if (last s1 == last s2) then
(lookupAns (n1 - 1) (n2 - 1) table) + 1 else
max (lookupAns n1 (n2 - 1) table) (lookupAns (n1 - 1) n2 table)
Why not:
if n1 == 0 || n2 == 0 then 0 else
if (last s1 == last s2) then
(lookupAns (n1 - 1) (n2 - 1) table) + 1 else
max (lookupAns n1 (n2 - 1) table) (lookupAns (n1 - 1) n2 table)
23:22: Warning: Redundant bracket
Found:
if (last s1 == last s2) then
(lookupAns (n1 - 1) (n2 - 1) table) + 1 else
max (lookupAns n1 (n2 - 1) table) (lookupAns (n1 - 1) n2 table)
Why not:
if last s1 == last s2 then (lookupAns (n1 - 1) (n2 - 1) table) + 1
else
max (lookupAns n1 (n2 - 1) table) (lookupAns (n1 - 1) n2 table)
26:21: Warning: Redundant bracket
Found:
(lookupAns (n1 - 1) (n2 - 1) table) + 1
Why not:
lookupAns (n1 - 1) (n2 - 1) table + 1