[Haskell-cafe] Help me TH code.
Serguey Zefirov
sergueyz at gmail.com
Wed Oct 27 04:53:53 EDT 2010
2010/10/27 Andy Stewart <lazycat.manatee at gmail.com>:
> Serguey Zefirov <sergueyz at gmail.com> writes:
>> I think that you should use TH properly, without compiler and logical errors.
>>
>> What actually do you want?
> I'm build multi-processes communication program.
You don't need TH here, I think.
You can write a class Ask:
class Ask a where ask :: YourMonad a
and then instance it:
instance Ask Int where ask = liftIO $ do { putStrLn "Enter integer:";
l <- getLine; return $ read l}
instance Ask Char where ask = liftIO $ do { putStrLn "Enter char:"; l
<- getLine; return $ head l}
instance Ask String where ask = liftIO $ do { putStrLn "Enter
string:"; l <- getLine; return l}
instance (Ask a, Ask b, Ask c) => Ask (a,b,c) where ask = liftIO $ do
{ a <- ask; b <- ask; c <- ask; return (a,b,c)}
You can pass ask values between processes, receiving results of asking.
TH is great and good, but it is that only when you absolutely
exhausted of usual Haskell options.
More information about the Haskell-Cafe
mailing list