haskell - This code is supposed to find a single Int in a list that is not dividable by 3 and then say False -
test4 :: [int] -> bool test4 [] = false test4 (x:xs) | mod x 3 /= 0 = false | otherwise = true i'd code find (not first) number of list can't divided three, , false.
i started learning haskell.
you need keep searching list if encounter number divisible 3. otherwise clause needs recursively call function.
test4 :: [int] -> bool test4 [] = true test4 (x:xs) | mod x 3 /= 0 = false | otherwise = test4 xs but i'd advise avoid writing low-level pattern-matching-and-recursion code when can. haskell's high-level language! in plain english, want function test whether of elements in list divisible 3. that's all :: (a -> bool) -> [a] -> bool function for:
test4 = (\x -> x `mod` 3 == 0) i think version clearer , easier read, being shorter.
Comments
Post a Comment