Search code examples
haskellnon-exhaustive-patterns

Non-exhaustive patterns in function haskell


I think I am missing the case where there's a one element list but I can't find a way to write it can someone help me?

getBoard :: [String] -> [String]
getBoard (h:t) | isLOL h = h: getBoard (t)
               | otherwise = []


isLOL :: String -> Bool
isLOL [ ] = True
isLOL (h:t) | h>='a' && h<='z' || h >='A' && h<='Z' = isLOL t
            | otherwise = False

Solution

  • getBoard [] = []
    

    is the line you want. Like this:

    getBoard :: [String] -> [String]
    getBoard [] = []
    getBoard (h:t) | isLOL h = h: getBoard (t)
                   | otherwise = []
    
    
    isLOL :: String -> Bool
    isLOL [] = True
    isLOL (h:t) | h>='a' && h<='z' || h >='A' && h<='Z' = isLOL t
                | otherwise = False