template haskell -- include a file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

template haskell -- include a file?

Jason Dusek
  I'd like to use template Haskell to include as a string in a
  Haskell file. How do I do it?

  Is there any lengthy documentation with examples for Template
  Haskell? The pages linked to from `haskell.org` are a little
  sparse.

--
_jsn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: template haskell -- include a file?

Bulat Ziganshin-2
Hello Jason,

Friday, September 12, 2008, 11:47:44 PM, you wrote:

>   I'd like to use template Haskell to include as a string in a
>   Haskell file. How do I do it?

TH is a typed macrosystem - you generate special datastructure
representing haskell code rather than untyped strings

>   Is there any lengthy documentation with examples for Template
>   Haskell? The pages linked to from `haskell.org` are a little
>   sparse.

look for "Bulat's tutorials" at http://haskell.org/haskellwiki/Template_Haskell
although they both are unfinished

--
Best regards,
 Bulat                            mailto:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: template haskell -- include a file?

Bugzilla from alfonso.acosta@gmail.com
In reply to this post by Jason Dusek
On Fri, Sep 12, 2008 at 9:47 PM, Jason Dusek <[hidden email]> wrote:
>  I'd like to use template Haskell to include as a string in a
>  Haskell file. How do I do it?

I presume you mean Include a string from the outside world with a IO
action (a file, keyborad, etc ...)

--
module EmbedStr (embedStr) where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax (lift)

embedStr :: IO String -> ExpQ
embedStr readStr = lift =<< runIO readStr
--

For example, to get asked about the string you want to embed during
compilation ...

$ ghci -XTemplateHaskell EmbedStr.hs
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling EmbedStr         ( EmbedStr.hs, interpreted )
Ok, modules loaded: EmbedStr.
*EmbedStr> let myStr = $(embedStr ((putStrLn "What string?") >> getLine))
Loading package array-0.1.0.0 ... linking ... done.
Loading package packedstring-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package pretty-1.0.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
What String?
Foo
*EmbedStr> myStr
"Foo"
*EmbedStr>



>  Is there any lengthy documentation with examples for Template
>  Haskell? The pages linked to from `haskell.org` are a little
>  sparse.

Uhm, I only know about

http://www.haskell.org/haskellwiki/Template_Haskell#Template_Haskell_tutorials_and_papers

I particularly like Mark Snyder's Template Haskell chapter on the
Software Generation and Configuration Report , but the link is broken
:(
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: template haskell -- include a file?

Jason Dusek
  Thank you!

--
_jsn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: template haskell -- include a file?

Jason Dusek
In reply to this post by Bugzilla from alfonso.acosta@gmail.com
Alfonso Acosta <[hidden email]> wrote:
> Uhm, I only know about
>
> http://www.haskell.org/haskellwiki/Template_Haskell#Template_Haskell_tutorials_and_papers

  Oh, I guess I missed the wiki.

--
_jsn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe