Get a sublist in Haskell

前端 未结 4 2097
死守一世寂寞
死守一世寂寞 2021-02-18 20:50

Probably an easy one, but I\'ve looked through the docs and googled for examples and I\'m still not sure of the answer.

If I have a list like this:

[1,2,         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-02-18 21:22

    You may be interested in Data.Vector (slice).

    ghci> import Data.Vector
    ghci> let v = fromList [1..10]
    ghci> v
    fromList [1,2,3,4,5,6,7,8,9,10]
    ghci> slice 4 5 v
    fromList [5,6,7,8,9]
    

    Note that slice in Data.Vector takes as inputs the beginning index and the length of the slice.

提交回复
热议问题