Re: [Haskell-cafe] Type checking the content of a string

2013-02-23 Thread Corentin Dupont
Up on that, anybody already tried to load an haskell interpreter in a
QuasiQuoter?

On Sat, Feb 23, 2013 at 12:03 AM, Corentin Dupont corentin.dup...@gmail.com
 wrote:

 I'm trying to load my interpreter in the Q monad:

 cr :: QuasiQuoter
 cr = QuasiQuoter { quoteExp = quoteRuleFunc}

 quoteRuleFunc :: String - Q TH.Exp
 quoteRuleFunc s = do
res - runIO $ runInterpreter $ do
   setImports [Prelude, Language.Nomyx.Rule,
 Language.Nomyx.Expression, Language.Nomyx.Test,
Language.Nomyx.Examples, GHC.Base, Data.Maybe]
   interpret s (as :: RuleFunc)
case res of
   Right _ - [| s |]
   Left e - fail $ show e


  However, I always obtain an error durring compilation:

 ...
 Loading package XXX ... linking ... done.


 GHCi runtime linker: fatal error: I found a duplicate definition for symbol
__stginit_ghczm7zi4zi1_DsMeta
 whilst processing object file
/usr/lib/ghc/ghc-7.4.1/libHSghc-7.4.1.a
 This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
  loaded twice.
 GHCi cannot safely continue in this situation.  Exiting now.  Sorry.


 I vaguely understand that the interpreted modules are conflicting with the
 compiled ones...



 On Fri, Feb 22, 2013 at 11:51 PM, Corentin Dupont 
 corentin.dup...@gmail.com wrote:

 Great! That seems very powerful. So you can do what you want during
 compilation, readin files, send data over the network?
 Other question, in my example how can I halt the compilation if a test
 program is wrong?


 On Fri, Feb 22, 2013 at 8:30 PM, Francesco Mazzoli f...@mazzo.li wrote:

 At Fri, 22 Feb 2013 19:43:51 +0100,
 Corentin Dupont wrote:
  Hi Adam,
  that looks interresting. I'm totally new to TH and QuasiQuotes, though.
  Can I run IO in a QuasiQuoter? I can run my own interpreter.

 Yes, you can:
 
 http://hackage.haskell.org/packages/archive/template-haskell/2.8.0.0/doc/html/Language-Haskell-TH.html#v:runIO
 .

 Francesco




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


Re: [Haskell-cafe] Type checking the content of a string

2013-02-23 Thread Brent Yorgey
On Fri, Feb 22, 2013 at 06:44:06PM +0100, Corentin Dupont wrote:
 Hi all,
 I have a program able to read another program as a string, and interpret it
 (using Hint).
 I'd like to make unit tests, so I have a file Test.hs containing a serie
 of test programs as strings.
 However, how could I be sure that these test program are syntactically
 valid, at compile time?

If you just want to check whether a program is syntactically valid,
you can use the haskell-src-exts package to parse it.  If you also
want to do some type checking you can try the haskell-type-exts
package.

-Brent

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


Re: [Haskell-cafe] Type checking the content of a string

2013-02-23 Thread Corentin Dupont
Finally, I solved the problem using typeOf instead of interpret:

cr :: QuasiQuoter
cr = QuasiQuoter { quoteExp = quoteRuleFunc}

quoteRuleFunc :: String - Q TH.Exp
quoteRuleFunc s = do
   res - runIO $ runInterpreter $ do
  setImports [Prelude, Language.Nomyx.Expression]
  typeOf s
   case res of
  Right RuleFunc - [| s |]
  Right _ - fail $ Rule doesn't typecheck
  Left e - fail $ show e

I don't know really why, but now it's working very well!

On Sat, Feb 23, 2013 at 7:56 PM, Daniel GorĂ­n jcpetru...@gmail.com wrote:

 Hi Corentin,

 I've never used TH, but from what I understand, trying to combine hint and
 TH would be redundant (even if it worked): whatever String you can evaluate
 using hint, you can evaluate it directly in TH. Is this not the case?

  Cheers,
 Daniel

 On Feb 23, 2013, at 6:53 PM, Corentin Dupont wrote:

  Hi Daniel,
  Did you already tried to use Hint in a QuasiQuote? This would come handy
 to check at compile time the validity of some strings...
  However I have the error hereunder.
  The duplicate symbol found in the object file is in fact the first
 symbol in this file. So I guess GHCi tries to load it twice...
  Best,
  Corentin
 
 
  On Sat, Feb 23, 2013 at 12:03 AM, Corentin Dupont 
 corentin.dup...@gmail.com wrote:
  I'm trying to load my interpreter in the Q monad:
 
  cr :: QuasiQuoter
  cr = QuasiQuoter { quoteExp = quoteRuleFunc}
 
  quoteRuleFunc :: String - Q TH.Exp
  quoteRuleFunc s = do
 res - runIO $ runInterpreter $ do
setImports [Prelude, Language.Nomyx.Rule,
 Language.Nomyx.Expression, Language.Nomyx.Test,
 Language.Nomyx.Examples, GHC.Base, Data.Maybe]
interpret s (as :: RuleFunc)
 case res of
Right _ - [| s |]
Left e - fail $ show e
 
 
   However, I always obtain an error during compilation:
 
  ...
  Loading package XXX ... linking ... done.
 
 
  GHCi runtime linker: fatal error: I found a duplicate definition for
 symbol
 __stginit_ghczm7zi4zi1_DsMeta
  whilst processing object file
 /usr/lib/ghc/ghc-7.4.1/libHSghc-7.4.1.a
  This could be caused by:
 * Loading two different object files which export the same symbol
 * Specifying the same object file twice on the GHCi command line
 * An incorrect `package.conf' entry, causing some object to be
   loaded twice.
  GHCi cannot safely continue in this situation.  Exiting now.  Sorry.
 
 
  I vaguely understand that the interpreted modules are conflicting with
 the compiled ones...
 
 
 
  On Fri, Feb 22, 2013 at 11:51 PM, Corentin Dupont 
 corentin.dup...@gmail.com wrote:
  Great! That seems very powerful. So you can do what you want during
 compilation, readin files, send data over the network?
  Other question, in my example how can I halt the compilation if a test
 program is wrong?
 
 
  On Fri, Feb 22, 2013 at 8:30 PM, Francesco Mazzoli f...@mazzo.li wrote:
  At Fri, 22 Feb 2013 19:43:51 +0100,
  Corentin Dupont wrote:
   Hi Adam,
   that looks interresting. I'm totally new to TH and QuasiQuotes, though.
   Can I run IO in a QuasiQuoter? I can run my own interpreter.
 
  Yes, you can:
  
 http://hackage.haskell.org/packages/archive/template-haskell/2.8.0.0/doc/html/Language-Haskell-TH.html#v:runIO
 .
 
  Francesco
 
 
 


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


[Haskell-cafe] Type checking the content of a string

2013-02-22 Thread Corentin Dupont
Hi all,
I have a program able to read another program as a string, and interpret it
(using Hint).
I'd like to make unit tests, so I have a file Test.hs containing a serie
of test programs as strings.
However, how could I be sure that these test program are syntactically
valid, at compile time?
Those programs should have the type RuleFunc.

I tried some TH:
printProg :: Q Exp - String
printProg p = unsafePerformIO $ do
   expr - runQ p
   return $ pprint expr

myTest = printProg [| my test program :: RuleFunc |]

But it's not very satisfatory yet. When pretty printing TH changes the
program quite a bit and my interpreter cannot compile it due to scoping
problems.
I'd like to have my test program copied back as is. Is it possible? Any
other solutions?

Thanks a lot!
Corentin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type checking the content of a string

2013-02-22 Thread adam vogt
On Fri, Feb 22, 2013 at 12:44 PM, Corentin Dupont
corentin.dup...@gmail.com wrote:
 Hi all,
 I have a program able to read another program as a string, and interpret it
 (using Hint).
 I'd like to make unit tests, so I have a file Test.hs containing a serie
 of test programs as strings.
 However, how could I be sure that these test program are syntactically
 valid, at compile time?

Hi Corentin,

You could write the test programs like:

test1 :: String
test1 = [qq| x+1 == 3 |]

Where qq is a QuasiQuoter you have to define. It could try to parse
the string with http://hackage.haskell.org/package/haskell-src-exts,
and if that succeeds, returns the original string.

--
Adam

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


Re: [Haskell-cafe] Type checking the content of a string

2013-02-22 Thread Corentin Dupont
Hi Adam,
that looks interresting. I'm totally new to TH and QuasiQuotes, though.
Can I run IO in a QuasiQuoter? I can run my own interpreter.



On Fri, Feb 22, 2013 at 7:12 PM, adam vogt vogt.a...@gmail.com wrote:

 On Fri, Feb 22, 2013 at 12:44 PM, Corentin Dupont
 corentin.dup...@gmail.com wrote:
  Hi all,
  I have a program able to read another program as a string, and interpret
 it
  (using Hint).
  I'd like to make unit tests, so I have a file Test.hs containing a
 serie
  of test programs as strings.
  However, how could I be sure that these test program are syntactically
  valid, at compile time?

 Hi Corentin,

 You could write the test programs like:

 test1 :: String
 test1 = [qq| x+1 == 3 |]

 Where qq is a QuasiQuoter you have to define. It could try to parse
 the string with http://hackage.haskell.org/package/haskell-src-exts,
 and if that succeeds, returns the original string.

 --
 Adam

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


Re: [Haskell-cafe] Type checking the content of a string

2013-02-22 Thread Francesco Mazzoli
At Fri, 22 Feb 2013 19:43:51 +0100,
Corentin Dupont wrote:
 Hi Adam,
 that looks interresting. I'm totally new to TH and QuasiQuotes, though.
 Can I run IO in a QuasiQuoter? I can run my own interpreter.

Yes, you can:
http://hackage.haskell.org/packages/archive/template-haskell/2.8.0.0/doc/html/Language-Haskell-TH.html#v:runIO.

Francesco

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


Re: [Haskell-cafe] Type checking the content of a string

2013-02-22 Thread Corentin Dupont
Great! That seems very powerful. So you can do what you want during
compilation, readin files, send data over the network?
Other question, in my example how can I halt the compilation if a test
program is wrong?

On Fri, Feb 22, 2013 at 8:30 PM, Francesco Mazzoli f...@mazzo.li wrote:

 At Fri, 22 Feb 2013 19:43:51 +0100,
 Corentin Dupont wrote:
  Hi Adam,
  that looks interresting. I'm totally new to TH and QuasiQuotes, though.
  Can I run IO in a QuasiQuoter? I can run my own interpreter.

 Yes, you can:
 
 http://hackage.haskell.org/packages/archive/template-haskell/2.8.0.0/doc/html/Language-Haskell-TH.html#v:runIO
 .

 Francesco

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


Re: [Haskell-cafe] Type checking the content of a string

2013-02-22 Thread Corentin Dupont
I'm trying to load my interpreter in the Q monad:

cr :: QuasiQuoter
cr = QuasiQuoter { quoteExp = quoteRuleFunc}

quoteRuleFunc :: String - Q TH.Exp
quoteRuleFunc s = do
   res - runIO $ runInterpreter $ do
  setImports [Prelude, Language.Nomyx.Rule,
Language.Nomyx.Expression, Language.Nomyx.Test,
   Language.Nomyx.Examples, GHC.Base, Data.Maybe]
  interpret s (as :: RuleFunc)
   case res of
  Right _ - [| s |]
  Left e - fail $ show e


 However, I always obtain an error durring compilation:

...
Loading package XXX ... linking ... done.


GHCi runtime linker: fatal error: I found a duplicate definition for symbol
   __stginit_ghczm7zi4zi1_DsMeta
whilst processing object file
   /usr/lib/ghc/ghc-7.4.1/libHSghc-7.4.1.a
This could be caused by:
   * Loading two different object files which export the same symbol
   * Specifying the same object file twice on the GHCi command line
   * An incorrect `package.conf' entry, causing some object to be
 loaded twice.
GHCi cannot safely continue in this situation.  Exiting now.  Sorry.


I vaguely understand that the interpreted modules are conflicting with the
compiled ones...


On Fri, Feb 22, 2013 at 11:51 PM, Corentin Dupont corentin.dup...@gmail.com
 wrote:

 Great! That seems very powerful. So you can do what you want during
 compilation, readin files, send data over the network?
 Other question, in my example how can I halt the compilation if a test
 program is wrong?


 On Fri, Feb 22, 2013 at 8:30 PM, Francesco Mazzoli f...@mazzo.li wrote:

 At Fri, 22 Feb 2013 19:43:51 +0100,
 Corentin Dupont wrote:
  Hi Adam,
  that looks interresting. I'm totally new to TH and QuasiQuotes, though.
  Can I run IO in a QuasiQuoter? I can run my own interpreter.

 Yes, you can:
 
 http://hackage.haskell.org/packages/archive/template-haskell/2.8.0.0/doc/html/Language-Haskell-TH.html#v:runIO
 .

 Francesco



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