[Haskell-beginners] Combining IO and Either function to "EitherT e IO a"
fuuzetsu at fuuzetsu.co.uk
Wed Mar 5 14:31:59 UTC 2014
On 05/03/14 13:53, Nathan Hüsken wrote:
> I have a function
> |func1 :: IO String
> and another:
> |func2 :: String -> Either String String
> and I want to combine them, giving the output of the first as the input
> as the second.
> |func3 :: IO (Either String String)
> func3 = do
> tmp <- func1
> return (func2 tmp)
This is just ‘fmap func2 func1’ or using the operator, ‘func2 <$> func1’.
> Ok, possible. But I rather would like a result of type "EitherT String
> IO String".
> So how can I combine these function in a smart way, to get the needed
After using ‘func2 <$> func1’ we have ‘IO (Either String String)’ as you
point out. The ‘EitherT’ constructor has type ‘m (Either e a)’. Here if
m = IO, e = String, a = String so we have exactly what we need:
> > :t EitherT $ func2 <$> func1
> EitherT $ func2 <$> func1 :: EitherT String IO String
> Beginners mailing list
> Beginners at haskell.org
More information about the Beginners