File: BadInsort.hs

package info (click to toggle)
hat 2.02-12
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,296 kB
  • ctags: 668
  • sloc: haskell: 64,394; ansic: 6,112; sh: 888; makefile: 451
file content (13 lines) | stat: -rw-r--r-- 382 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
sort :: Ord a => [a] -> [a]
-- FAULT (1): missing equation for [] argument
sort (x:xs) = insert x (sort xs)

insert :: Ord a => a -> [a] -> [a]
insert x []     = [x]
insert x (y:ys) = if x <= y
                  -- FAULT (2): y missing from result
		  then x : ys
                  -- FAULT (3): recursive call is same
		  else y : insert x (y:ys)

main = putStrLn (sort "program")