Skip to content

Instantly share code, notes, and snippets.

@Jimexist
Created July 15, 2013 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jimexist/6000975 to your computer and use it in GitHub Desktop.
Save Jimexist/6000975 to your computer and use it in GitHub Desktop.
takeR
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