Browse Source

Project 18

completed
Craige McWhirter 7 months ago
parent
commit
0eb4c0395e
Signed by: craige GPG Key ID: 7DBA9F5689EFB6AA
  1. 14
      slice.hs

14
slice.hs

@ -0,0 +1,14 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wno-orphans #-}
-- Extract a slice from a list.
-- Given two indices, i and k, the slice is the list containing the elements
-- between the i'th and k'th element of the original list (both limits
-- included). Start counting the elements with 1.
slice :: [a] -> Int -> Int -> [a]
slice [] _ _ = []
slice _ _ 0 = []
slice (x:xs) 1 n = x:slice xs 1 (n-1)
slice (_:xs) m n = slice xs (m-1) (n-1)
Loading…
Cancel
Save