Monday 6 June 2016

Haskell: Convert list of a to list of IO a


Sample.hs
liftToIO :: [a] -> [IO a]
liftToIO [] = []
liftToIO (x:xs) = (return x) : liftToIO xs

Prelude> :load Sample.hs
[1 of 1] Compiling Main             ( Sample.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> let res1 = [1, 2, 3, 4]
*Main> :t res1
res1 :: Num t => [t]
*Main> 
*Main> let res2 = liftToIO res1
*Main> 
*Main> :t res2
res2 :: Num a => [IO a]


Previous                                                 Next                                                 Home

No comments:

Post a Comment