• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Template Haskell とか
 

Template Haskell とか

on

  • 2,521 views

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

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

Statistics

Views

Total Views
2,521
Views on SlideShare
2,511
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 とか Template Haskell とか Presentation Transcript

  • 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 <- 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) )
  • 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) )
  • 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) )
  • 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 $ randomRIO (0,1) let nm = mkName (["a", "b"] !! rnd) m <- [d| main = $(varE $ mkName "a") |] t <- valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] return (t:m) )
  • [ |
  • [ | [| 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 |] [$ident| function f() {..} |] DSL
  • [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL
  • [ | [| putStrLn “hogehoge” |] [t| String |] [d| main = putStrLn |] [$ident| function f() {..} |] DSL )JavaScript (
  • splice [d| main = $(varE $ mkName "a") |] splice [d| main = ‘a |] TH a `a ``String
  • {-# 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) )
  • valD (varP nm) (normalB [| putStrLn " ( ´ `) " |]) [] [d| $(varP nm) = putStrLn “ ( ´ `) ” |] …… …… ghci > runQ [d| main = putStrLn “hoge” |]
  • 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, NoBindS $ f"oh",l, NoBindS $ InfixE(Just$ f"speaking")(f"words")(Just $ f "wisdom"),l]
  • 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]
  • 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
  • reify IO reify Q