[Haskell-cafe] List operation question

Eric Olander olandere at gmail.com
Sun Feb 4 13:44:10 EST 2007


Hi,
   I'm still somewhat new to Haskell, so I'm wondering if there are better
ways I could implement the following functions, especially shiftl:

>> moves the first element to the end of the list
    shiftr :: [a] -> [a]
    shiftr [] = []
    shiftr (x:y) = y ++ [x]

>> moves the last element to the head of the list
    shiftl :: [a] -> [a]
    shiftl [] = []
    shiftl x = [last x] ++ init x

-Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070204/b8765c3b/attachment.htm


More information about the Haskell-Cafe mailing list