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

Like this? Share it with your network

Share

Template Haskell とか

on

  • 2,659 views

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

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

Statistics

Views

Total Views
2,659
Views on SlideShare
2,649
Embed Views
10

Actions

Likes
1
Downloads
11
Comments
0

2 Embeds 10

https://twitter.com 6
http://www.slideshare.net 4

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Template Haskell とか Presentation Transcript

  • 1. Template Haskell konn
  • 2. Template Haskell
  • 3. Template Haskell Haskell
  • 4. Template Haskell Haskell
  • 5. Template Haskell Haskell Q
  • 6. Template Haskell Haskell Q C preprocessor
  • 7. TH
  • 8. TH Haskell
  • 9. TH Haskell IO compile-time wxWidgets Network...
  • 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. 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. 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. Splice
  • 14. Splice (Q )
  • 15. Splice (Q ) splice splice
  • 16. Splice (Q ) splice splice “ ”
  • 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. [ |
  • 19. [ | [| putStrLn “hogehoge” |]
  • 20. [ | [| putStrLn “hogehoge” |] [t| String |]
  • 21. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |]
  • 22. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |]
  • 23. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL
  • 24. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL
  • 25. [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL )JavaScript (
  • 26. splice [d| main = $(varE $ mkName "a") |] splice [d| main = ‘a |] TH a `a ``String
  • 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. valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] [d| $(varP nm) = putStrLn “ ( ´ `) ” |] …… …… ghci > runQ [d| main = putStrLn “hoge” |]
  • 29. Sucks GHC TH Ver.UP (ex. HOC )
  • 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. 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. 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. reify IO reify Q