SO 20911133/compare-coordinates-with-filter

1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Play where

import Text.XML.Light	

main = do c <- getContents
	  let Just el = parseXMLDoc c

          --putStrLn $ showElement (processa el)
	  --putStrLn (show(next el))
          --putStrLn (show(getInfo el))
	  putStrLn (show(tab(getLimits el)))
	  putStrLn (show(getOcupadas el))

--devolve elemento next

next :: Element -> Char
next t = if length (findChildren (unqual "next") t) == 0 then (' ')
	   	   else let next = (head(findChildren (unqual "next") t))
		            (Just x) = (findAttr (unqual "tile") next)
	      		in (head x) 

--getInfo

getInfo :: Element -> [ (Int, Int, Char, Char, (Char,Int)) ]
getInfo el = [ (getX ts, getY ts, getT ts, getO ts, (aux ts)) 
	     | ts <- findElements (unqual "tile") el ]

aux :: Element -> (Char,Int)
aux t = if length (findChildren (unqual "follower") t) == 0 then (' ',0)
	   	   else let fol = (head(findChildren (unqual "follower") t))
		            (Just x, Just y) = ((findAttr (unqual "type") fol),(findAttr (unqual "player") fol))
	      		in ((head x), read y) 

getX :: Element -> Int
getX el = let Just x = findAttr (unqual "x") el
	  in read x

getY :: Element -> Int
getY el = let Just y = findAttr (unqual "y") el
	  in read y

getT :: Element -> Char
getT el = let Just t = findAttr (unqual "type") el
    	  in head t 

getO :: Element -> Char
getO el = let Just o = findAttr (unqual "orientation") el
	  in head o

getOcupadas :: Element -> [(Int, Int)]
getOcupadas el = [ (getX ts, getY ts) 
	     | ts <- findElements (unqual "tile") el ]

--tabuleiro

getLimits :: Element -> (Int, Int, Int, Int)
getLimits el = let tiles = getInfo el
	       in (minimum [ x | (x,_,_,_,_) <- tiles],
		   maximum [ x | (x,_,_,_,_) <- tiles],
		   minimum [ y | (_,y,_,_,_) <- tiles],
		   maximum [ y | (_,y,_,_,_) <- tiles])

tab :: (Int, Int, Int, Int) -> [[(Int, Int)]]
tab (xm, xM, ym, yM) = [  [ (x,y) | x <- [xm .. xM]  ]
                                  | y <- [yM, yM-1 ..ym]  ]
12:11: Error: Use print
Found:
putStrLn (show (getOcupadas el))
Why not:
print (getOcupadas el)
17:13: Warning: Use null
Found:
length (findChildren (unqual "next") t) == 0
Why not:
null (findChildren (unqual "next") t)
Note: increases laziness
11:11: Error: Use print
Found:
putStrLn (show (tab (getLimits el)))
Why not:
print (tab (getLimits el))
17:63: Error: Redundant bracket
Found:
(' ')
Why not:
' '
18:25: Warning: Redundant bracket
Found:
let next = (head (findChildren (unqual "next") t))
(Just x) = (findAttr (unqual "tile") next)
in (head x)
Why not:
let next = head (findChildren (unqual "next") t)
(Just x) = (findAttr (unqual "tile") next)
in (head x)
18:25: Warning: Redundant bracket
Found:
let next = (head (findChildren (unqual "next") t))
(Just x) = (findAttr (unqual "tile") next)
in (head x)
Why not:
let next = (head (findChildren (unqual "next") t))
(Just x) = findAttr (unqual "tile") next
in (head x)
18:25: Warning: Redundant bracket
Found:
let next = (head (findChildren (unqual "next") t))
(Just x) = (findAttr (unqual "tile") next)
in (head x)
Why not:
let next = (head (findChildren (unqual "next") t))
(Just x) = (findAttr (unqual "tile") next)
in head x
25:16: Warning: Redundant bracket
Found:
(getX ts, getY ts, getT ts, getO ts, (aux ts))
Why not:
(getX ts, getY ts, getT ts, getO ts, aux ts)
29:12: Warning: Use null
Found:
length (findChildren (unqual "follower") t) == 0
Why not:
null (findChildren (unqual "follower") t)
Note: increases laziness
30:25: Warning: Redundant bracket
Found:
let fol = (head (findChildren (unqual "follower") t))
(Just x, Just y)
= ((findAttr (unqual "type") fol),
(findAttr (unqual "player") fol))
in ((head x), read y)
Why not:
let fol = head (findChildren (unqual "follower") t)
(Just x, Just y)
= ((findAttr (unqual "type") fol),
(findAttr (unqual "player") fol))
in ((head x), read y)
31:48: Warning: Redundant bracket
Found:
((findAttr (unqual "type") fol), (findAttr (unqual "player") fol))
Why not:
(findAttr (unqual "type") fol, (findAttr (unqual "player") fol))
31:48: Warning: Redundant bracket
Found:
((findAttr (unqual "type") fol), (findAttr (unqual "player") fol))
Why not:
((findAttr (unqual "type") fol), findAttr (unqual "player") fol)
32:28: Warning: Redundant bracket
Found:
((head x), read y)
Why not:
(head x, read y)