Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Serguey Zefirov
2010/10/27 Andy Stewart lazycat.mana...@gmail.com:
 Hi all,

 I want use TH write some function like below:

  data DataType = StringT
                | IntT
                | CharT

  parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN)

 Example:

  parse [(string, StringT), (001, IntT), (c, CharT)]

 will return:

  (string, 001, 'c')

 So how to use TH write 'parse' function?

I think that you should use TH properly, without compiler and logical errors.

What actually do you want?

I think that parse should have type (parse :: [(String, DataType)] - Q Exp).

I think that OverloadedStrings extension should serve you as well.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Andy Stewart
Serguey Zefirov sergu...@gmail.com writes:

 2010/10/27 Andy Stewart lazycat.mana...@gmail.com:
 Hi all,

 I want use TH write some function like below:

  data DataType = StringT
                | IntT
                | CharT

  parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN)

 Example:

  parse [(string, StringT), (001, IntT), (c, CharT)]

 will return:

  (string, 001, 'c')

 So how to use TH write 'parse' function?

 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.

Example i have two processes : Client and Server.

At Client side, i pass [DataType] to Server, example:

  [StringT, IntT, CharT]

Server will handle user input with [DataType] 
and return result [String] to Client side, example:

  [string, 001, c]

Then at Client side, i need parse [String] to get real value:

  (string, 001, 'c')
  
Because, [DataType] have many different case, so i want pass [String]
between processes, and use TH parse result [String] at Client side.

Thanks,

  -- Andy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Jonas Almström Duregård
Unless you have a 'real' type for parse sometime during compile time, TH
won't be able to generate it. A good rule of thumbs is that if you can't
write the code yourself, then you can't get TH to do it either.

/J

On 27 October 2010 08:50, Andy Stewart lazycat.mana...@gmail.com wrote:

 Serguey Zefirov sergu...@gmail.com writes:

  2010/10/27 Andy Stewart lazycat.mana...@gmail.com:
  Hi all,
 
  I want use TH write some function like below:
 
   data DataType = StringT
 | IntT
 | CharT
 
   parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN)
 
  Example:
 
   parse [(string, StringT), (001, IntT), (c, CharT)]
 
  will return:
 
   (string, 001, 'c')
 
  So how to use TH write 'parse' function?
 
  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.

 Example i have two processes : Client and Server.

 At Client side, i pass [DataType] to Server, example:

  [StringT, IntT, CharT]

 Server will handle user input with [DataType]
 and return result [String] to Client side, example:

  [string, 001, c]

 Then at Client side, i need parse [String] to get real value:

  (string, 001, 'c')

 Because, [DataType] have many different case, so i want pass [String]
 between processes, and use TH parse result [String] at Client side.

 Thanks,

  -- Andy
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Serguey Zefirov
2010/10/27 Andy Stewart lazycat.mana...@gmail.com:
 Serguey Zefirov sergu...@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.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Help me TH code.

2010-10-26 Thread Andy Stewart
Hi all,

I want use TH write some function like below:

  data DataType = StringT
| IntT
| CharT

  parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN)

Example:
  
  parse [(string, StringT), (001, IntT), (c, CharT)]

will return:

  (string, 001, 'c')

So how to use TH write 'parse' function? 

Thanks!

  -- Andy

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe