/ Published in: Haskell
problem 20, (*) Remove the K'th element from a list
*Main> removeAt 1 "abcd"
"acd"
Trivial using a pure function. A bit more challenging if you use this problem to work up your Arrow-fu.
*Main> removeAt 1 "abcd"
"acd"
Trivial using a pure function. A bit more challenging if you use this problem to work up your Arrow-fu.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
{-# LANGUAGE Arrows #-} import Control.Arrow import Data.List list = "abcdefghijklmnop" -- the trivial version -- now new and improved! with Arrows for ultra-obfuscation! {- the arrowed function is easier to understand in its sugary form NOTE: the head and tail of the arrows are lambda values, so they can't be used inside the arrow's machinery. Also, to use this notation, you'll need the LANGUAGE Arrows pragma -} removeAt'' n = proc things -> do (begin, end) <- (\xs -> (xs, xs)) -< things returnA -< newlist -- This is equivalent, and shows how proc notation can -- simplify things removeAt''' n = proc things -> do returnA -< begin ++ end main = do putStrLn list
URL: http://haskell.org/haskellwiki/99_questions/11_to_20