0
Template Haskell
         konn
Template Haskell
Template Haskell

 Haskell
Template Haskell

 Haskell
Template Haskell

 Haskell




           Q
Template Haskell

 Haskell




           Q

 C preprocessor
TH
TH

Haskell
TH

     Haskell




IO

     compile-time wxWidgets Network...
RandomDef.hs
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH
import System.Random

$( do rnd...
RandomDef.hs
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH
import System.Random IO

$( do ...
Splice(                     )
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH
import System....
Splice
Splice
(Q   )
Splice
  (Q        )

splice

         splice
Splice
      (Q        )

    splice

             splice




“                     ”
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH
import System.Random

$( do rnd <- runIO $ r...
[   |
[   |
        [| putStrLn “hogehoge” |]
[   |
        [| putStrLn “hogehoge” |]
        [t| String |]
[   |
        [| putStrLn “hogehoge” |]
        [t| String |]
          [d| main = putStrLn |]
[   |
        [| putStrLn “hogehoge” |]
        [t| String |]
          [d| main = putStrLn |]
        [$ident| function f...
[   |
              [| putStrLn “hogehoge” |]
              [t| String |]
                [d| main = putStrLn |]
         ...
[   |
              [| putStrLn “hogehoge” |]
              [t| String |]
                [d| main = putStrLn |]
         ...
[   |
                [| putStrLn “hogehoge” |]
                [t| String |]
                  [d| main = putStrLn |]
   ...
splice
[d| main = $(varE $ mkName "a") |]

                       splice

                [d| main = ‘a |]         TH
   a...
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH
import System.Random

$( do rnd <- runIO $ r...
valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) []

          [d| $(varP nm) = putStrLn “ ( ´ `) ” |]

                ...
Sucks



GHC

 TH                Ver.UP
      (ex. HOC )
lib2 =
   let
      l=LetS[ValD(VarP $ mkName"it")(NormalB(f"be"))[]]
      f=VarE . mkName
   in
      DoE [ l, l, l, NoB...
lib2 =
   let
      l=LetS[ValD(VarP $ mkName"it")(NormalB(f"be"))[]]
      f=VarE . mkName
   in
      DoE [ l, l, l, NoB...
lib2 =
   let
      l=LetS[ValD(VarP $ mkName"it")(NormalB(f"be"))[]]
      f=VarE . mkName
   in
      DoE [ l, l, l, NoB...
reify




        IO   reify

  Q
Template Haskell とか
Template Haskell とか
Upcoming SlideShare
Loading in...5
×

Template Haskell とか

2,066

Published on

Template Haskell について即席でまとめた資料

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,066
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide






























  • Transcript of "Template Haskell とか"

    1. 1. Template Haskell konn
    2. 2. Template Haskell
    3. 3. Template Haskell Haskell
    4. 4. Template Haskell Haskell
    5. 5. Template Haskell Haskell Q
    6. 6. Template Haskell Haskell Q C preprocessor
    7. 7. TH
    8. 8. TH Haskell
    9. 9. TH Haskell IO compile-time wxWidgets Network...
    10. 10. RandomDef.hs {-# LANGUAGE TemplateHaskell #-} module Main where import Language.Haskell.TH import System.Random $( do rnd <- runIO $ randomRIO (0,1) let nm = mkName (["a", "b"] !! rnd) m <- [d| main = $(varE $ mkName "a") |] t <- valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] return (t:m) )
    11. 11. RandomDef.hs {-# LANGUAGE TemplateHaskell #-} module Main where import Language.Haskell.TH import System.Random IO $( do rnd <- runIO $ randomRIO (0,1) let nm = mkName (["a", "b"] !! rnd) m <- [d| main = $(varE $ mkName "a") |] t <- valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] return (t:m) )
    12. 12. Splice( ) {-# LANGUAGE TemplateHaskell #-} module Main where import Language.Haskell.TH import System.Random $( do rnd <- runIO $ randomRIO (0,1) let nm = mkName (["a", "b"] !! rnd) m <- [d| main = $(varE $ mkName "a") |] t <- valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] return (t:m) )
    13. 13. Splice
    14. 14. Splice (Q )
    15. 15. Splice (Q ) splice splice
    16. 16. Splice (Q ) splice splice “ ”
    17. 17. {-# LANGUAGE TemplateHaskell #-} module Main where import Language.Haskell.TH import System.Random $( do rnd <- runIO $ randomRIO (0,1) let nm = mkName (["a", "b"] !! rnd) m <- [d| main = $(varE $ mkName "a") |] t <- valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] return (t:m) )
    18. 18. [ |
    19. 19. [ | [| putStrLn “hogehoge” |]
    20. 20. [ | [| putStrLn “hogehoge” |] [t| String |]
    21. 21. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |]
    22. 22. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |]
    23. 23. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL
    24. 24. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL
    25. 25. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL )JavaScript (
    26. 26. splice [d| main = $(varE $ mkName "a") |] splice [d| main = ‘a |] TH a `a ``String
    27. 27. {-# LANGUAGE TemplateHaskell #-} module Main where import Language.Haskell.TH import System.Random $( do rnd <- runIO $ randomRIO (0,1) let nm = mkName (["a", "b"] !! rnd) m <- [d| main = $(varE $ mkName "a") |] t <- valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] return (t:m) )
    28. 28. valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] [d| $(varP nm) = putStrLn “ ( ´ `) ” |] …… …… ghci > runQ [d| main = putStrLn “hoge” |]
    29. 29. Sucks GHC TH Ver.UP (ex. HOC )
    30. 30. lib2 = let l=LetS[ValD(VarP $ mkName"it")(NormalB(f"be"))[]] f=VarE . mkName in DoE [ l, l, l, NoBindS $ f"oh",l, NoBindS $ InfixE(Just$ f"speaking")(f"words")(Just $ f "wisdom"),l]
    31. 31. lib2 = let l=LetS[ValD(VarP $ mkName"it")(NormalB(f"be"))[]] f=VarE . mkName in DoE [ l, l, l, NoBindS $ f"oh",l, NoBindS $ InfixE(Just$ f"speaking")(f"words")(Just $ f "wisdom"),l]
    32. 32. lib2 = let l=LetS[ValD(VarP $ mkName"it")(NormalB(f"be"))[]] f=VarE . mkName in DoE [ l, l, l, NoBindS $ f"oh",l, NoBindS $ InfixE(Just$ f"speaking")(f"words")(Just $ f "wisdom"),l] do let it = be let it = be let it = be oh let it = be speaking `words` wisdom let it = be
    33. 33. reify IO reify Q
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×