Created
July 15, 2013 15:43
-
-
Save jimexist/6000975 to your computer and use it in GitHub Desktop.
takeR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Test.QuickCheck | |
takeR :: Int -> [a] -> [a] | |
takeR n _ | n <= 0 = [] | |
takeR n l | otherwise = go (drop n l) l | |
where go [] y = y | |
go (_:xs) (_:ys) = go xs ys | |
prop_length s n = (length s >= n && n >= 0) ==> length (takeR n s) == n | |
where types = (s :: [Char], n :: Int ) | |
prop_full s n = (length s == n) ==> (takeR n s) == s | |
where types = (s :: [Char], n :: Int ) | |
prop_empty s n = (n <= 0) ==> (takeR n s) == [] | |
where types = (s :: [Char], n :: Int ) | |
prop_isomorph s n = reverse (take n (reverse s)) == takeR n s | |
where types = (s :: [Char], n :: Int ) | |
main = do | |
quickCheck prop_empty | |
quickCheck prop_full | |
quickCheck prop_isomorph | |
quickCheck prop_length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment