add something to a list
Adrian Hey
ahey@iee.org
Sun, 17 Feb 2002 19:12:10 +0000
On Sunday 17 February 2002 17:04, Cagdas Ozgenc wrote:
> > getPath :: Path -> IO Path
> > getPath currentPath = do
> > piece <- getLine
> > if piece == "" then return currentPath
> > else getPath (piece:currentPath)
> >
> > initialCurrentPath::Path
> > initialCurrentPath = []
> >
> > main :: IO ()
> > main = do
> > path <- getPath initialCurrentPath
> > putStrLn (show path)
> Hi Adrian,
>
> How can I add a function that sorts this list that I read from the user and
> accumulate using the function that you described? I am not asking for a
> sort algorithm of course, I am just wondering how to feed the IO Path as an
> input to a sort function? Is it suppose to look like this:
>
> sort :: IO Path -> IO Path
>
> or
>
> sort :: IO Path -> Path
>
> How do you iterate over IO Path?
>
> Thanks for taking time.
I don't know what iterating over something means
(the opposite of iterating under something I suppose)
I think you want something like this..
import List (sort)
sortGet :: IO Path -> IO Path
sortGet get = do
got <- get
return (sort got)
or maybe even..
import Monad (liftM)
sortGet :: IO Path -> IO Path
sortGet = liftM sort
Regards
--
Adrian Hey