ฉันมีฟังก์ชั่นสามอย่างที่ค้นหาองค์ประกอบที่ n ของรายการ:
nthElement :: [a] -> Int -> Maybe a 
nthElement [] a = Nothing
nthElement (x:xs) a | a <= 0 = Nothing
                    | a == 1 = Just x
                    | a > 1 = nthElement xs (a-1)
nthElementIf :: [a] -> Int -> Maybe a
nthElementIf [] a = Nothing
nthElementIf (x:xs) a = if a <= 1
                        then if a <= 0 
                             then Nothing
                             else Just x -- a == 1
                        else nthElementIf xs (a-1)                           
nthElementCases :: [a] -> Int -> Maybe a
nthElementCases [] a = Nothing
nthElementCases (x:xs) a = case a <= 0 of
                             True -> Nothing
                             False -> case a == 1 of
                                        True -> Just x
                                        False -> nthElementCases xs (a-1)
ในความคิดของฉันฟังก์ชั่นแรกคือการนำไปใช้งานที่ดีที่สุดเพราะมีความรัดกุมที่สุด แต่มีอะไรเกี่ยวกับการใช้งานอีกสองรายการที่จะทำให้ดีกว่านี้หรือไม่? คุณจะเลือกอย่างไรระหว่างการใช้ยามคำสั่ง if-then-else และกรณี?
case compare a 1 of ...
                
caseข้อความที่ซ้อนกันได้หากคุณใช้case compare a 0 of LT -> ... | EQ -> ... | GT -> ...