module Exercise_4 where {-H4.1.10-} editDistance :: Eq a => [a] -> [a] -> Int editDistance _ [] = 0 editDistance [] _ = 0 editDistance a b = editDistance' (length a) (length b) where editDistance' 0 0 = 0 editDistance' i 0 = i editDistance' 0 j = j editDistance' i j = min (min (if a!!(i-1) == b!!(j-1) then editDistance' (i-1) (j-1) else editDistance' (i-1) (j-1) +1) (if i > 1 && j > 1 && a!!(i-1) == b!!(j-2) && a!!(i-2) == b!!(j-1) then editDistance' (i-2) (j-2) +1 else 100)) (min (if i > 0 then editDistance' (i-1) j +1 else 100) (if j > 0 then editDistance' i (j-1) +1 else 100)) {-looks awful sorry-} {-H4.1.11-} {-WETT-} spellCorrect :: [String] -> [String] -> [[String]] spellCorrect [] _ = [] spellCorrect _ [] = [] spellCorrect d (x:xs) = [y |y<-d,editDistance x y == minEdit] :spellCorrect d xs where minEdit = minimum[editDistance x y|y<-d] {-TTEW-}