How do you write the function 'pairs' in Haskell?

前端 未结 4 603
萌比男神i
萌比男神i 2021-02-07 04:50

The pairs function needs to do something like this:

pairs [1, 2, 3, 4] -> [(1, 2), (2, 3), (3, 4)]
4条回答
  •  不思量自难忘°
    2021-02-07 05:34

    Call to the Aztec god of consecutive numbers:

    import Control.Monad (ap)
    import Control.Monad.Instances() -- for Monad ((->) a)
    
    foo = zip`ap`tail $ [1,2,3,4]
    

提交回复
热议问题