Advertisement
Madotsuki

Untitled

Sep 3rd, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-
  2. -- drop, take
  3. drop :: Int -> [a] -> [a]
  4. take :: Int -> [a] -> [a]
  5.  
  6. ghci> drop 10 [1..20]
  7. [11,12,13,14,15,16,17,18,19,20]
  8. it :: [Integer]
  9. ghci> take 10 [1..20]
  10. [1,2,3,4,5,6,7,8,9,10]
  11. it :: [Integer]
  12.  
  13. Truncates a list at a certain range. For drop, it will drop the first 10 slots in the list, and for take, it will take only the first 10 slots in the list. This is useful to cut-off something endless, like...
  14.  
  15. ghci> take 10 ( cycle [1,3,3,7] )
  16. [1,3,3,7,1,3,3,7,1,3]
  17. it :: [Integer]
  18.  
  19. -- filter
  20. filter :: (a -> Bool) -> [a] -> [a]
  21.  
  22. ghci> filter (>Yellow) [Red,Green,Blue,Violet,Orange,Yellow,Green]
  23. [Green,Blue,Violet,Green]
  24. it :: [Color]
  25.  
  26. Only keeps elements in a list that follow a certain condition given to it.
  27.  
  28. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement