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

adam vogt vogt.adam at gmail.com
Fri Feb 22 19:12:52 CET 2013


On Fri, Feb 22, 2013 at 12:44 PM, Corentin Dupont
<corentin.dupont at 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



More information about the Haskell-Cafe mailing list