Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Language.Haskell.TH
import Control.Monad
import Control.Applicative
mapMT :: Int -> ExpQ -> ExpQ
mapMT count f = do
vars <- replicateM count $ newName "x"
let ops = '(<$>):repeat '(<*>)
lamE [tupP $ map varP vars] $ foldl (\x -> \(op, y) -> (appE (appE (varE op) x) (appE f (varE y)))) (conE $ tupleDataName count) (zip ops vars)
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Language.Haskell.TH
import Control.Monad
mapT :: Int -> ExpQ -> ExpQ
mapT count f = do
vars <- replicateM count $ newName "x"
lamE [tupP $ map varP vars] (tupE $ map (appE f . varE) vars)
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
module THUtility where
import Language.Haskell.TH
import Control.Monad
import Control.Applicative
mapT :: Int -> ExpQ -> ExpQ
mapT count f = do
vars <- replicateM count $ newName "x"
lamE [tupP $ map varP vars] (tupE $ map (appE f . varE) vars)
drawString :: DrawingArea -> DrawWindow -> RGB -> Coordinate -> String -> IO ()
drawString drawArea drawWin (r, g, b) (x, y) str = do
let gcVal = newGCValues {foreground = Color r g b}
gc <- gcNewWithValues drawWin gcVal
layout <- widgetCreateLayout drawArea str
layoutSetText layout str
layoutSetWrap layout WrapWholeWords
layoutSetWidth layout . Just $ 300
lineCount <- layoutGetLineCount layout
widgetSetSizeRequest drawArea 300 1000
-- タイムラインのフィールドにデータを描画
drawTimelineData :: GUI -> [Tweet] -> IO ()
drawTimelineData gui tweets = do
let home = homeTimeline gui
field = timelineField home
tlText = foldl (\s -> \t -> s ++ (show t) ++ "\n") "" tweets
-- 描画イベントを発生させる
GUI.drawString field (0, 0, 0) (0, 0) tlText
return ()
drawString :: DrawingArea -> RGB -> Coordinate -> String -> IO ()
drawString drawArea (r, g, b) (x, y) str = do
drawWin <- widgetGetDrawWindow drawArea
let gcVal = newGCValues {foreground = Color r g b}
gc <- gcNewWithValues drawWin gcVal
layout <- widgetCreateLayout drawArea str
layoutSetText layout str
layoutSetWrap layout WrapWholeWords
layoutSetWidth layout . Just $ 300
lineCount <- layoutGetLineCount layout